123456789101112131415161718192021222324252627282930313233343536373839404142 |
- // ---------------------------------------------------------------------------------------------------------------------
- // TESTS: Async Validator
- // ---------------------------------------------------------------------------------------------------------------------
- import { FormControl, Validators, ValidationErrors } from '@angular/forms';
- // For the simple async validator
- import { Observable, of } from 'rxjs';
- import { delay, map } from 'rxjs/internal/operators';
- const testAsyncValidator = (fc: FormControl): Observable<ValidationErrors> => {
- return of(fc).pipe(delay(2000)).pipe(map(_fc => {
- console.log('Async validator got', _fc.value);
- return _fc.value.trim() !== '42' ? { isNot42: true } : null;
- }));
- };
- const model = {
- nonValidatedField: '',
- dynaformtest: {
- validatedField: ''
- }
- };
- const meta = {
- dynaformtest: {
- meta: {
- validatedField: {
- label: 'What\'s 30 + 12 ?',
- validators: Validators.required,
- asyncValidators: testAsyncValidator,
- valFailureMessages: {
- 'required': 'This field is required',
- 'is42': 'The only correct answer is 42'
- }
- }
- }
- }
- };
- export { model, meta };
|