diff --git a/src/max/validator.spec.ts b/src/max/validator.spec.ts index 186faed..63458a3 100644 --- a/src/max/validator.spec.ts +++ b/src/max/validator.spec.ts @@ -22,4 +22,9 @@ describe('Max', () => { expect(max(5)(control)).toEqual(error); }); + + it('should ignore date-time values', () => { + let control = new FormControl('2016-09-08'); + expect(max('2016-09-09')(control)).toBeNull(); + }); }); diff --git a/src/max/validator.ts b/src/max/validator.ts index df81aca..9b965cd 100644 --- a/src/max/validator.ts +++ b/src/max/validator.ts @@ -1,11 +1,12 @@ import { AbstractControl, Validators, ValidatorFn } from '@angular/forms'; -import { isPresent } from '../facade/lang'; +import { isPresent, isDate } from '../facade/lang'; export const max = (max: number): ValidatorFn => { return (control: AbstractControl): {[key: string]: boolean} => { if (!isPresent(max)) return null; if (isPresent(Validators.required(control))) return null; + if (isNaN(max) && isDate(new Date(max))) return null; let v: number = +control.value; return v <= +max ? null : {max: true}; diff --git a/src/min/validator.spec.ts b/src/min/validator.spec.ts index 2bbebb9..bdf86bd 100644 --- a/src/min/validator.spec.ts +++ b/src/min/validator.spec.ts @@ -16,4 +16,9 @@ describe('Min', () => { expect(min(10)(control)).toEqual(error); }); + + it('should ignore date-time values', () => { + let control = new FormControl('2016-09-10'); + expect(min('2016-09-09')(control)).toBeNull(); + }); }); diff --git a/src/min/validator.ts b/src/min/validator.ts index b00b70a..bc177dc 100644 --- a/src/min/validator.ts +++ b/src/min/validator.ts @@ -1,11 +1,12 @@ import { AbstractControl, Validators, ValidatorFn } from '@angular/forms'; -import { isPresent } from '../facade/lang'; +import { isPresent, isDate } from '../facade/lang'; export const min = (min: number): ValidatorFn => { return (control: AbstractControl): {[key: string]: boolean} => { if (!isPresent(min)) return null; if (isPresent(Validators.required(control))) return null; + if (isNaN(min) && isDate(new Date(min))) return null; let v: number = +control.value; return v >= +min ? null : {min: true};