Commit a0e66629 authored by Open Source Developer's avatar Open Source Developer
Browse files

min max limits

parent 4f3a9ba5
...@@ -11,6 +11,7 @@ import { BehaviorSubject, Subscription } from 'rxjs/Rx'; ...@@ -11,6 +11,7 @@ import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types'; import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { VALID_CAPACITY_PATTERN} from '../../constants'; import { VALID_CAPACITY_PATTERN} from '../../constants';
import {maxValue} from '../../constants'; import {maxValue} from '../../constants';
import {minValue} from '../../constants';
import { import {
...@@ -54,10 +55,13 @@ import { ...@@ -54,10 +55,13 @@ import {
<input type="number" formControlName="capacity" min="1" max="10" ng-min="1" ng-max="99" > <input type="number" formControlName="capacity" min="1" max="10" ng-min="1" ng-max="99" >
<div class="alert alert-danger" *ngIf="formGroup.get('capacity').touched && formGroup.get('capacity').hasError('maxValue')"> <div class="alert alert-danger" *ngIf="formGroup.get('capacity').touched && formGroup.get('capacity').hasError('maxValue')">
Συμπληρώστε την διαθεσιμότητα σας σε τμήματα ! Παρακαλώ συμπληρώστε ένα μικρότερο αριθμό!
</div>
<div class="alert alert-danger" *ngIf="formGroup.get('capacity').touched && formGroup.get('capacity').hasError('minValue')">
Παρακαλώ συμπληρώστε ένα μεγαλύτερο αριθμό!
</div> </div>
<div class="alert alert-danger" *ngIf="formGroup.get('capacity').touched && formGroup.get('capacity').hasError('required')"> <div class="alert alert-danger" *ngIf="formGroup.get('capacity').touched && formGroup.get('capacity').hasError('required')">
Παρακαλώ συμπληρώστε ένα μικρότερο αριθμό! Συμπληρώστε την διαθεσιμότητα σας σε τμήματα !
</div> </div>
<button type="button" class="btn-primary btn-sm pull-right" (click) ="saveCapacity()"> <button type="button" class="btn-primary btn-sm pull-right" (click) ="saveCapacity()">
...@@ -158,7 +162,7 @@ import { ...@@ -158,7 +162,7 @@ import {
tomeas: ['', []], tomeas: ['', []],
taxi: ['', []], taxi: ['', []],
specialit: ['', []], specialit: ['', []],
capacity: ['', [Validators.pattern(VALID_CAPACITY_PATTERN),Validators.required, maxValue(99)]], capacity: ['', [Validators.pattern(VALID_CAPACITY_PATTERN),Validators.required, maxValue(99), minValue(1)]],
}); });
} }
......
...@@ -44,8 +44,6 @@ export const CRITERIA_INIT = 'CRITERIA_INIT'; ...@@ -44,8 +44,6 @@ export const CRITERIA_INIT = 'CRITERIA_INIT';
export const VALID_NAMES_PATTERN = '[A-Za-zΑ-ΩΆΈΉΊΙΎΌΏα-ωάέήίΐύόώ ]*$'; export const VALID_NAMES_PATTERN = '[A-Za-zΑ-ΩΆΈΉΊΙΎΌΏα-ωάέήίΐύόώ ]*$';
export const VALID_ADDRESS_PATTERN = '[0-9A-Za-zΑ-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$'; export const VALID_ADDRESS_PATTERN = '[0-9A-Za-zΑ-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$';
export const VALID_ADDRESSTK_PATTERN = '[0-9 ]*$'; export const VALID_ADDRESSTK_PATTERN = '[0-9 ]*$';
<<<<<<< HEAD
export const VALID_DIGITS_PATTERN = '69[0-9]*$';
export const VALID_CAPACITY_PATTERN = '[0-9]*$'; export const VALID_CAPACITY_PATTERN = '[0-9]*$';
...@@ -78,3 +76,14 @@ export function maxValue(max: Number): ValidatorFn { ...@@ -78,3 +76,14 @@ export function maxValue(max: Number): ValidatorFn {
return null; return null;
}; };
} }
export function minValue(min: Number): ValidatorFn {
return (control: AbstractControl): {[key: string]: any} => {
const input = control.value,
isValid = input < 1;
if(isValid)
return { 'minValue': {min} }
else
return null;
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment