diff --git a/packages/forms/src/directives.ts b/packages/forms/src/directives.ts index cd7a8cb9b3..101a6103c9 100644 --- a/packages/forms/src/directives.ts +++ b/packages/forms/src/directives.ts @@ -58,7 +58,9 @@ export const SHARED_FORM_DIRECTIVES: Type[] = [ NgControlStatus, NgControlStatusGroup, RequiredValidator, + MinValidator, MinLengthValidator, + MaxValidator, MaxLengthValidator, PatternValidator, CheckboxRequiredValidator, diff --git a/packages/forms/src/forms.ts b/packages/forms/src/forms.ts index 81caaa2dca..b1f882d1d4 100644 --- a/packages/forms/src/forms.ts +++ b/packages/forms/src/forms.ts @@ -38,7 +38,7 @@ export {FormArrayName} from './directives/reactive_directives/form_group_name'; export {FormGroupName} from './directives/reactive_directives/form_group_name'; export {NgSelectOption, SelectControlValueAccessor} from './directives/select_control_value_accessor'; export {SelectMultipleControlValueAccessor} from './directives/select_multiple_control_value_accessor'; -export {AsyncValidator, AsyncValidatorFn, CheckboxRequiredValidator, EmailValidator, MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValidator, ValidationErrors, Validator, ValidatorFn} from './directives/validators'; +export {AsyncValidator, AsyncValidatorFn, CheckboxRequiredValidator, EmailValidator, MaxLengthValidator, MaxValidator, MinLengthValidator, MinValidator, PatternValidator, RequiredValidator, ValidationErrors, Validator, ValidatorFn} from './directives/validators'; export {FormBuilder} from './form_builder'; export {AbstractControl, FormArray, FormControl, FormGroup} from './model'; export {NG_ASYNC_VALIDATORS, NG_VALIDATORS, Validators} from './validators'; diff --git a/packages/forms/test/template_integration_spec.ts b/packages/forms/test/template_integration_spec.ts index e734eabcf3..9368dd859a 100644 --- a/packages/forms/test/template_integration_spec.ts +++ b/packages/forms/test/template_integration_spec.ts @@ -879,99 +879,95 @@ export function main() { describe('validation directives', () => { - // TODO(kara): activate when we start exporting max validator dir - xit('should should validate max', fakeAsync(() => { - const fixture = initTest(NgModelMaxValidator); - fixture.componentInstance.max = 10; - fixture.detectChanges(); - tick(); + it('should should validate max', fakeAsync(() => { + const fixture = initTest(NgModelMaxValidator); + fixture.componentInstance.max = 10; + fixture.detectChanges(); + tick(); - const max = fixture.debugElement.query(By.css('input')); - const form = fixture.debugElement.children[0].injector.get(NgForm); + const max = fixture.debugElement.query(By.css('input')); + const form = fixture.debugElement.children[0].injector.get(NgForm); - max.nativeElement.value = ''; - dispatchEvent(max.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(true); + max.nativeElement.value = ''; + dispatchEvent(max.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(true); - max.nativeElement.value = 11; - dispatchEvent(max.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(false); + max.nativeElement.value = 11; + dispatchEvent(max.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(false); - max.nativeElement.value = 9; - dispatchEvent(max.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(true); - })); + max.nativeElement.value = 9; + dispatchEvent(max.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(true); + })); - // TODO(kara): activate when we start exporting max validator dir - xit('should validate max for strings', fakeAsync(() => { - const fixture = initTest(NgModelMaxValidator); - fixture.componentInstance.max = 10; - fixture.detectChanges(); - tick(); + it('should validate max for strings', fakeAsync(() => { + const fixture = initTest(NgModelMaxValidator); + fixture.componentInstance.max = 10; + fixture.detectChanges(); + tick(); - const max = fixture.debugElement.query(By.css('input')); - const form = fixture.debugElement.children[0].injector.get(NgForm); + const max = fixture.debugElement.query(By.css('input')); + const form = fixture.debugElement.children[0].injector.get(NgForm); - max.nativeElement.value = '11'; - dispatchEvent(max.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(false); + max.nativeElement.value = '11'; + dispatchEvent(max.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(false); - max.nativeElement.value = '9'; - dispatchEvent(max.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(true); - })); + max.nativeElement.value = '9'; + dispatchEvent(max.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(true); + })); - // TODO(kara): activate when we start exporting min validator dir - xit('should should validate min', fakeAsync(() => { - const fixture = initTest(NgModelMinValidator); - fixture.componentInstance.min = 10; - fixture.detectChanges(); - tick(); + it('should should validate min', fakeAsync(() => { + const fixture = initTest(NgModelMinValidator); + fixture.componentInstance.min = 10; + fixture.detectChanges(); + tick(); - const min = fixture.debugElement.query(By.css('input')); - const form = fixture.debugElement.children[0].injector.get(NgForm); + const min = fixture.debugElement.query(By.css('input')); + const form = fixture.debugElement.children[0].injector.get(NgForm); - min.nativeElement.value = ''; - dispatchEvent(min.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(true); + min.nativeElement.value = ''; + dispatchEvent(min.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(true); - min.nativeElement.value = 11; - dispatchEvent(min.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(true); + min.nativeElement.value = 11; + dispatchEvent(min.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(true); - min.nativeElement.value = 9; - dispatchEvent(min.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(false); - })); + min.nativeElement.value = 9; + dispatchEvent(min.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(false); + })); - // TODO(kara): activate when we start exporting min validator dir - xit('should should validate min for strings', fakeAsync(() => { - const fixture = initTest(NgModelMinValidator); - fixture.componentInstance.min = 10; - fixture.detectChanges(); - tick(); + it('should should validate min for strings', fakeAsync(() => { + const fixture = initTest(NgModelMinValidator); + fixture.componentInstance.min = 10; + fixture.detectChanges(); + tick(); - const min = fixture.debugElement.query(By.css('input')); - const form = fixture.debugElement.children[0].injector.get(NgForm); + const min = fixture.debugElement.query(By.css('input')); + const form = fixture.debugElement.children[0].injector.get(NgForm); - min.nativeElement.value = '11'; - dispatchEvent(min.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(true); + min.nativeElement.value = '11'; + dispatchEvent(min.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(true); - min.nativeElement.value = '9'; - dispatchEvent(min.nativeElement, 'input'); - fixture.detectChanges(); - expect(form.valid).toEqual(false); - })); + min.nativeElement.value = '9'; + dispatchEvent(min.nativeElement, 'input'); + fixture.detectChanges(); + expect(form.valid).toEqual(false); + })); it('required validator should validate checkbox', fakeAsync(() => { diff --git a/tools/public_api_guard/forms/forms.d.ts b/tools/public_api_guard/forms/forms.d.ts index 5015340bef..398d80c064 100644 --- a/tools/public_api_guard/forms/forms.d.ts +++ b/tools/public_api_guard/forms/forms.d.ts @@ -352,6 +352,14 @@ export declare class MaxLengthValidator implements Validator, OnChanges { validate(c: AbstractControl): ValidationErrors | null; } +/** @experimental */ +export declare class MaxValidator implements Validator, OnChanges { + max: string; + ngOnChanges(changes: SimpleChanges): void; + registerOnValidatorChange(fn: () => void): void; + validate(c: AbstractControl): ValidationErrors | null; +} + /** @stable */ export declare class MinLengthValidator implements Validator, OnChanges { minlength: string; @@ -360,6 +368,14 @@ export declare class MinLengthValidator implements Validator, OnChanges { validate(c: AbstractControl): ValidationErrors | null; } +/** @experimental */ +export declare class MinValidator implements Validator, OnChanges { + min: string; + ngOnChanges(changes: SimpleChanges): void; + registerOnValidatorChange(fn: () => void): void; + validate(c: AbstractControl): ValidationErrors | null; +} + /** @stable */ export declare const NG_ASYNC_VALIDATORS: InjectionToken<(Function | Validator)[]>;