1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { InjectionToken, ɵisObservable as isObservable, ɵisPromise as isPromise } from '@angular/core';
|
---|
9 | import { forkJoin, from } from 'rxjs';
|
---|
10 | import { map } from 'rxjs/operators';
|
---|
11 | function isEmptyInputValue(value) {
|
---|
12 | // we don't check for string here so it also works with arrays
|
---|
13 | return value == null || value.length === 0;
|
---|
14 | }
|
---|
15 | function hasValidLength(value) {
|
---|
16 | // non-strict comparison is intentional, to check for both `null` and `undefined` values
|
---|
17 | return value != null && typeof value.length === 'number';
|
---|
18 | }
|
---|
19 | /**
|
---|
20 | * @description
|
---|
21 | * An `InjectionToken` for registering additional synchronous validators used with
|
---|
22 | * `AbstractControl`s.
|
---|
23 | *
|
---|
24 | * @see `NG_ASYNC_VALIDATORS`
|
---|
25 | *
|
---|
26 | * @usageNotes
|
---|
27 | *
|
---|
28 | * ### Providing a custom validator
|
---|
29 | *
|
---|
30 | * The following example registers a custom validator directive. Adding the validator to the
|
---|
31 | * existing collection of validators requires the `multi: true` option.
|
---|
32 | *
|
---|
33 | * ```typescript
|
---|
34 | * @Directive({
|
---|
35 | * selector: '[customValidator]',
|
---|
36 | * providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
|
---|
37 | * })
|
---|
38 | * class CustomValidatorDirective implements Validator {
|
---|
39 | * validate(control: AbstractControl): ValidationErrors | null {
|
---|
40 | * return { 'custom': true };
|
---|
41 | * }
|
---|
42 | * }
|
---|
43 | * ```
|
---|
44 | *
|
---|
45 | * @publicApi
|
---|
46 | */
|
---|
47 | export const NG_VALIDATORS = new InjectionToken('NgValidators');
|
---|
48 | /**
|
---|
49 | * @description
|
---|
50 | * An `InjectionToken` for registering additional asynchronous validators used with
|
---|
51 | * `AbstractControl`s.
|
---|
52 | *
|
---|
53 | * @see `NG_VALIDATORS`
|
---|
54 | *
|
---|
55 | * @publicApi
|
---|
56 | */
|
---|
57 | export const NG_ASYNC_VALIDATORS = new InjectionToken('NgAsyncValidators');
|
---|
58 | /**
|
---|
59 | * A regular expression that matches valid e-mail addresses.
|
---|
60 | *
|
---|
61 | * At a high level, this regexp matches e-mail addresses of the format `local-part@tld`, where:
|
---|
62 | * - `local-part` consists of one or more of the allowed characters (alphanumeric and some
|
---|
63 | * punctuation symbols).
|
---|
64 | * - `local-part` cannot begin or end with a period (`.`).
|
---|
65 | * - `local-part` cannot be longer than 64 characters.
|
---|
66 | * - `tld` consists of one or more `labels` separated by periods (`.`). For example `localhost` or
|
---|
67 | * `foo.com`.
|
---|
68 | * - A `label` consists of one or more of the allowed characters (alphanumeric, dashes (`-`) and
|
---|
69 | * periods (`.`)).
|
---|
70 | * - A `label` cannot begin or end with a dash (`-`) or a period (`.`).
|
---|
71 | * - A `label` cannot be longer than 63 characters.
|
---|
72 | * - The whole address cannot be longer than 254 characters.
|
---|
73 | *
|
---|
74 | * ## Implementation background
|
---|
75 | *
|
---|
76 | * This regexp was ported over from AngularJS (see there for git history):
|
---|
77 | * https://github.com/angular/angular.js/blob/c133ef836/src/ng/directive/input.js#L27
|
---|
78 | * It is based on the
|
---|
79 | * [WHATWG version](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address) with
|
---|
80 | * some enhancements to incorporate more RFC rules (such as rules related to domain names and the
|
---|
81 | * lengths of different parts of the address). The main differences from the WHATWG version are:
|
---|
82 | * - Disallow `local-part` to begin or end with a period (`.`).
|
---|
83 | * - Disallow `local-part` length to exceed 64 characters.
|
---|
84 | * - Disallow total address length to exceed 254 characters.
|
---|
85 | *
|
---|
86 | * See [this commit](https://github.com/angular/angular.js/commit/f3f5cf72e) for more details.
|
---|
87 | */
|
---|
88 | const EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
---|
89 | /**
|
---|
90 | * @description
|
---|
91 | * Provides a set of built-in validators that can be used by form controls.
|
---|
92 | *
|
---|
93 | * A validator is a function that processes a `FormControl` or collection of
|
---|
94 | * controls and returns an error map or null. A null map means that validation has passed.
|
---|
95 | *
|
---|
96 | * @see [Form Validation](/guide/form-validation)
|
---|
97 | *
|
---|
98 | * @publicApi
|
---|
99 | */
|
---|
100 | export class Validators {
|
---|
101 | /**
|
---|
102 | * @description
|
---|
103 | * Validator that requires the control's value to be greater than or equal to the provided number.
|
---|
104 | *
|
---|
105 | * @usageNotes
|
---|
106 | *
|
---|
107 | * ### Validate against a minimum of 3
|
---|
108 | *
|
---|
109 | * ```typescript
|
---|
110 | * const control = new FormControl(2, Validators.min(3));
|
---|
111 | *
|
---|
112 | * console.log(control.errors); // {min: {min: 3, actual: 2}}
|
---|
113 | * ```
|
---|
114 | *
|
---|
115 | * @returns A validator function that returns an error map with the
|
---|
116 | * `min` property if the validation check fails, otherwise `null`.
|
---|
117 | *
|
---|
118 | * @see `updateValueAndValidity()`
|
---|
119 | *
|
---|
120 | */
|
---|
121 | static min(min) {
|
---|
122 | return minValidator(min);
|
---|
123 | }
|
---|
124 | /**
|
---|
125 | * @description
|
---|
126 | * Validator that requires the control's value to be less than or equal to the provided number.
|
---|
127 | *
|
---|
128 | * @usageNotes
|
---|
129 | *
|
---|
130 | * ### Validate against a maximum of 15
|
---|
131 | *
|
---|
132 | * ```typescript
|
---|
133 | * const control = new FormControl(16, Validators.max(15));
|
---|
134 | *
|
---|
135 | * console.log(control.errors); // {max: {max: 15, actual: 16}}
|
---|
136 | * ```
|
---|
137 | *
|
---|
138 | * @returns A validator function that returns an error map with the
|
---|
139 | * `max` property if the validation check fails, otherwise `null`.
|
---|
140 | *
|
---|
141 | * @see `updateValueAndValidity()`
|
---|
142 | *
|
---|
143 | */
|
---|
144 | static max(max) {
|
---|
145 | return maxValidator(max);
|
---|
146 | }
|
---|
147 | /**
|
---|
148 | * @description
|
---|
149 | * Validator that requires the control have a non-empty value.
|
---|
150 | *
|
---|
151 | * @usageNotes
|
---|
152 | *
|
---|
153 | * ### Validate that the field is non-empty
|
---|
154 | *
|
---|
155 | * ```typescript
|
---|
156 | * const control = new FormControl('', Validators.required);
|
---|
157 | *
|
---|
158 | * console.log(control.errors); // {required: true}
|
---|
159 | * ```
|
---|
160 | *
|
---|
161 | * @returns An error map with the `required` property
|
---|
162 | * if the validation check fails, otherwise `null`.
|
---|
163 | *
|
---|
164 | * @see `updateValueAndValidity()`
|
---|
165 | *
|
---|
166 | */
|
---|
167 | static required(control) {
|
---|
168 | return requiredValidator(control);
|
---|
169 | }
|
---|
170 | /**
|
---|
171 | * @description
|
---|
172 | * Validator that requires the control's value be true. This validator is commonly
|
---|
173 | * used for required checkboxes.
|
---|
174 | *
|
---|
175 | * @usageNotes
|
---|
176 | *
|
---|
177 | * ### Validate that the field value is true
|
---|
178 | *
|
---|
179 | * ```typescript
|
---|
180 | * const control = new FormControl('', Validators.requiredTrue);
|
---|
181 | *
|
---|
182 | * console.log(control.errors); // {required: true}
|
---|
183 | * ```
|
---|
184 | *
|
---|
185 | * @returns An error map that contains the `required` property
|
---|
186 | * set to `true` if the validation check fails, otherwise `null`.
|
---|
187 | *
|
---|
188 | * @see `updateValueAndValidity()`
|
---|
189 | *
|
---|
190 | */
|
---|
191 | static requiredTrue(control) {
|
---|
192 | return requiredTrueValidator(control);
|
---|
193 | }
|
---|
194 | /**
|
---|
195 | * @description
|
---|
196 | * Validator that requires the control's value pass an email validation test.
|
---|
197 | *
|
---|
198 | * Tests the value using a [regular
|
---|
199 | * expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
|
---|
200 | * pattern suitable for common usecases. The pattern is based on the definition of a valid email
|
---|
201 | * address in the [WHATWG HTML
|
---|
202 | * specification](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address) with
|
---|
203 | * some enhancements to incorporate more RFC rules (such as rules related to domain names and the
|
---|
204 | * lengths of different parts of the address).
|
---|
205 | *
|
---|
206 | * The differences from the WHATWG version include:
|
---|
207 | * - Disallow `local-part` (the part before the `@` symbol) to begin or end with a period (`.`).
|
---|
208 | * - Disallow `local-part` to be longer than 64 characters.
|
---|
209 | * - Disallow the whole address to be longer than 254 characters.
|
---|
210 | *
|
---|
211 | * If this pattern does not satisfy your business needs, you can use `Validators.pattern()` to
|
---|
212 | * validate the value against a different pattern.
|
---|
213 | *
|
---|
214 | * @usageNotes
|
---|
215 | *
|
---|
216 | * ### Validate that the field matches a valid email pattern
|
---|
217 | *
|
---|
218 | * ```typescript
|
---|
219 | * const control = new FormControl('bad@', Validators.email);
|
---|
220 | *
|
---|
221 | * console.log(control.errors); // {email: true}
|
---|
222 | * ```
|
---|
223 | *
|
---|
224 | * @returns An error map with the `email` property
|
---|
225 | * if the validation check fails, otherwise `null`.
|
---|
226 | *
|
---|
227 | * @see `updateValueAndValidity()`
|
---|
228 | *
|
---|
229 | */
|
---|
230 | static email(control) {
|
---|
231 | return emailValidator(control);
|
---|
232 | }
|
---|
233 | /**
|
---|
234 | * @description
|
---|
235 | * Validator that requires the length of the control's value to be greater than or equal
|
---|
236 | * to the provided minimum length. This validator is also provided by default if you use the
|
---|
237 | * the HTML5 `minlength` attribute. Note that the `minLength` validator is intended to be used
|
---|
238 | * only for types that have a numeric `length` property, such as strings or arrays. The
|
---|
239 | * `minLength` validator logic is also not invoked for values when their `length` property is 0
|
---|
240 | * (for example in case of an empty string or an empty array), to support optional controls. You
|
---|
241 | * can use the standard `required` validator if empty values should not be considered valid.
|
---|
242 | *
|
---|
243 | * @usageNotes
|
---|
244 | *
|
---|
245 | * ### Validate that the field has a minimum of 3 characters
|
---|
246 | *
|
---|
247 | * ```typescript
|
---|
248 | * const control = new FormControl('ng', Validators.minLength(3));
|
---|
249 | *
|
---|
250 | * console.log(control.errors); // {minlength: {requiredLength: 3, actualLength: 2}}
|
---|
251 | * ```
|
---|
252 | *
|
---|
253 | * ```html
|
---|
254 | * <input minlength="5">
|
---|
255 | * ```
|
---|
256 | *
|
---|
257 | * @returns A validator function that returns an error map with the
|
---|
258 | * `minlength` property if the validation check fails, otherwise `null`.
|
---|
259 | *
|
---|
260 | * @see `updateValueAndValidity()`
|
---|
261 | *
|
---|
262 | */
|
---|
263 | static minLength(minLength) {
|
---|
264 | return minLengthValidator(minLength);
|
---|
265 | }
|
---|
266 | /**
|
---|
267 | * @description
|
---|
268 | * Validator that requires the length of the control's value to be less than or equal
|
---|
269 | * to the provided maximum length. This validator is also provided by default if you use the
|
---|
270 | * the HTML5 `maxlength` attribute. Note that the `maxLength` validator is intended to be used
|
---|
271 | * only for types that have a numeric `length` property, such as strings or arrays.
|
---|
272 | *
|
---|
273 | * @usageNotes
|
---|
274 | *
|
---|
275 | * ### Validate that the field has maximum of 5 characters
|
---|
276 | *
|
---|
277 | * ```typescript
|
---|
278 | * const control = new FormControl('Angular', Validators.maxLength(5));
|
---|
279 | *
|
---|
280 | * console.log(control.errors); // {maxlength: {requiredLength: 5, actualLength: 7}}
|
---|
281 | * ```
|
---|
282 | *
|
---|
283 | * ```html
|
---|
284 | * <input maxlength="5">
|
---|
285 | * ```
|
---|
286 | *
|
---|
287 | * @returns A validator function that returns an error map with the
|
---|
288 | * `maxlength` property if the validation check fails, otherwise `null`.
|
---|
289 | *
|
---|
290 | * @see `updateValueAndValidity()`
|
---|
291 | *
|
---|
292 | */
|
---|
293 | static maxLength(maxLength) {
|
---|
294 | return maxLengthValidator(maxLength);
|
---|
295 | }
|
---|
296 | /**
|
---|
297 | * @description
|
---|
298 | * Validator that requires the control's value to match a regex pattern. This validator is also
|
---|
299 | * provided by default if you use the HTML5 `pattern` attribute.
|
---|
300 | *
|
---|
301 | * @usageNotes
|
---|
302 | *
|
---|
303 | * ### Validate that the field only contains letters or spaces
|
---|
304 | *
|
---|
305 | * ```typescript
|
---|
306 | * const control = new FormControl('1', Validators.pattern('[a-zA-Z ]*'));
|
---|
307 | *
|
---|
308 | * console.log(control.errors); // {pattern: {requiredPattern: '^[a-zA-Z ]*$', actualValue: '1'}}
|
---|
309 | * ```
|
---|
310 | *
|
---|
311 | * ```html
|
---|
312 | * <input pattern="[a-zA-Z ]*">
|
---|
313 | * ```
|
---|
314 | *
|
---|
315 | * ### Pattern matching with the global or sticky flag
|
---|
316 | *
|
---|
317 | * `RegExp` objects created with the `g` or `y` flags that are passed into `Validators.pattern`
|
---|
318 | * can produce different results on the same input when validations are run consecutively. This is
|
---|
319 | * due to how the behavior of `RegExp.prototype.test` is
|
---|
320 | * specified in [ECMA-262](https://tc39.es/ecma262/#sec-regexpbuiltinexec)
|
---|
321 | * (`RegExp` preserves the index of the last match when the global or sticky flag is used).
|
---|
322 | * Due to this behavior, it is recommended that when using
|
---|
323 | * `Validators.pattern` you **do not** pass in a `RegExp` object with either the global or sticky
|
---|
324 | * flag enabled.
|
---|
325 | *
|
---|
326 | * ```typescript
|
---|
327 | * // Not recommended (since the `g` flag is used)
|
---|
328 | * const controlOne = new FormControl('1', Validators.pattern(/foo/g));
|
---|
329 | *
|
---|
330 | * // Good
|
---|
331 | * const controlTwo = new FormControl('1', Validators.pattern(/foo/));
|
---|
332 | * ```
|
---|
333 | *
|
---|
334 | * @param pattern A regular expression to be used as is to test the values, or a string.
|
---|
335 | * If a string is passed, the `^` character is prepended and the `$` character is
|
---|
336 | * appended to the provided string (if not already present), and the resulting regular
|
---|
337 | * expression is used to test the values.
|
---|
338 | *
|
---|
339 | * @returns A validator function that returns an error map with the
|
---|
340 | * `pattern` property if the validation check fails, otherwise `null`.
|
---|
341 | *
|
---|
342 | * @see `updateValueAndValidity()`
|
---|
343 | *
|
---|
344 | */
|
---|
345 | static pattern(pattern) {
|
---|
346 | return patternValidator(pattern);
|
---|
347 | }
|
---|
348 | /**
|
---|
349 | * @description
|
---|
350 | * Validator that performs no operation.
|
---|
351 | *
|
---|
352 | * @see `updateValueAndValidity()`
|
---|
353 | *
|
---|
354 | */
|
---|
355 | static nullValidator(control) {
|
---|
356 | return nullValidator(control);
|
---|
357 | }
|
---|
358 | static compose(validators) {
|
---|
359 | return compose(validators);
|
---|
360 | }
|
---|
361 | /**
|
---|
362 | * @description
|
---|
363 | * Compose multiple async validators into a single function that returns the union
|
---|
364 | * of the individual error objects for the provided control.
|
---|
365 | *
|
---|
366 | * @returns A validator function that returns an error map with the
|
---|
367 | * merged error objects of the async validators if the validation check fails, otherwise `null`.
|
---|
368 | *
|
---|
369 | * @see `updateValueAndValidity()`
|
---|
370 | *
|
---|
371 | */
|
---|
372 | static composeAsync(validators) {
|
---|
373 | return composeAsync(validators);
|
---|
374 | }
|
---|
375 | }
|
---|
376 | /**
|
---|
377 | * Validator that requires the control's value to be greater than or equal to the provided number.
|
---|
378 | * See `Validators.min` for additional information.
|
---|
379 | */
|
---|
380 | export function minValidator(min) {
|
---|
381 | return (control) => {
|
---|
382 | if (isEmptyInputValue(control.value) || isEmptyInputValue(min)) {
|
---|
383 | return null; // don't validate empty values to allow optional controls
|
---|
384 | }
|
---|
385 | const value = parseFloat(control.value);
|
---|
386 | // Controls with NaN values after parsing should be treated as not having a
|
---|
387 | // minimum, per the HTML forms spec: https://www.w3.org/TR/html5/forms.html#attr-input-min
|
---|
388 | return !isNaN(value) && value < min ? { 'min': { 'min': min, 'actual': control.value } } : null;
|
---|
389 | };
|
---|
390 | }
|
---|
391 | /**
|
---|
392 | * Validator that requires the control's value to be less than or equal to the provided number.
|
---|
393 | * See `Validators.max` for additional information.
|
---|
394 | */
|
---|
395 | export function maxValidator(max) {
|
---|
396 | return (control) => {
|
---|
397 | if (isEmptyInputValue(control.value) || isEmptyInputValue(max)) {
|
---|
398 | return null; // don't validate empty values to allow optional controls
|
---|
399 | }
|
---|
400 | const value = parseFloat(control.value);
|
---|
401 | // Controls with NaN values after parsing should be treated as not having a
|
---|
402 | // maximum, per the HTML forms spec: https://www.w3.org/TR/html5/forms.html#attr-input-max
|
---|
403 | return !isNaN(value) && value > max ? { 'max': { 'max': max, 'actual': control.value } } : null;
|
---|
404 | };
|
---|
405 | }
|
---|
406 | /**
|
---|
407 | * Validator that requires the control have a non-empty value.
|
---|
408 | * See `Validators.required` for additional information.
|
---|
409 | */
|
---|
410 | export function requiredValidator(control) {
|
---|
411 | return isEmptyInputValue(control.value) ? { 'required': true } : null;
|
---|
412 | }
|
---|
413 | /**
|
---|
414 | * Validator that requires the control's value be true. This validator is commonly
|
---|
415 | * used for required checkboxes.
|
---|
416 | * See `Validators.requiredTrue` for additional information.
|
---|
417 | */
|
---|
418 | export function requiredTrueValidator(control) {
|
---|
419 | return control.value === true ? null : { 'required': true };
|
---|
420 | }
|
---|
421 | /**
|
---|
422 | * Validator that requires the control's value pass an email validation test.
|
---|
423 | * See `Validators.email` for additional information.
|
---|
424 | */
|
---|
425 | export function emailValidator(control) {
|
---|
426 | if (isEmptyInputValue(control.value)) {
|
---|
427 | return null; // don't validate empty values to allow optional controls
|
---|
428 | }
|
---|
429 | return EMAIL_REGEXP.test(control.value) ? null : { 'email': true };
|
---|
430 | }
|
---|
431 | /**
|
---|
432 | * Validator that requires the length of the control's value to be greater than or equal
|
---|
433 | * to the provided minimum length. See `Validators.minLength` for additional information.
|
---|
434 | */
|
---|
435 | export function minLengthValidator(minLength) {
|
---|
436 | return (control) => {
|
---|
437 | if (isEmptyInputValue(control.value) || !hasValidLength(control.value)) {
|
---|
438 | // don't validate empty values to allow optional controls
|
---|
439 | // don't validate values without `length` property
|
---|
440 | return null;
|
---|
441 | }
|
---|
442 | return control.value.length < minLength ?
|
---|
443 | { 'minlength': { 'requiredLength': minLength, 'actualLength': control.value.length } } :
|
---|
444 | null;
|
---|
445 | };
|
---|
446 | }
|
---|
447 | /**
|
---|
448 | * Validator that requires the length of the control's value to be less than or equal
|
---|
449 | * to the provided maximum length. See `Validators.maxLength` for additional information.
|
---|
450 | */
|
---|
451 | export function maxLengthValidator(maxLength) {
|
---|
452 | return (control) => {
|
---|
453 | return hasValidLength(control.value) && control.value.length > maxLength ?
|
---|
454 | { 'maxlength': { 'requiredLength': maxLength, 'actualLength': control.value.length } } :
|
---|
455 | null;
|
---|
456 | };
|
---|
457 | }
|
---|
458 | /**
|
---|
459 | * Validator that requires the control's value to match a regex pattern.
|
---|
460 | * See `Validators.pattern` for additional information.
|
---|
461 | */
|
---|
462 | export function patternValidator(pattern) {
|
---|
463 | if (!pattern)
|
---|
464 | return nullValidator;
|
---|
465 | let regex;
|
---|
466 | let regexStr;
|
---|
467 | if (typeof pattern === 'string') {
|
---|
468 | regexStr = '';
|
---|
469 | if (pattern.charAt(0) !== '^')
|
---|
470 | regexStr += '^';
|
---|
471 | regexStr += pattern;
|
---|
472 | if (pattern.charAt(pattern.length - 1) !== '$')
|
---|
473 | regexStr += '$';
|
---|
474 | regex = new RegExp(regexStr);
|
---|
475 | }
|
---|
476 | else {
|
---|
477 | regexStr = pattern.toString();
|
---|
478 | regex = pattern;
|
---|
479 | }
|
---|
480 | return (control) => {
|
---|
481 | if (isEmptyInputValue(control.value)) {
|
---|
482 | return null; // don't validate empty values to allow optional controls
|
---|
483 | }
|
---|
484 | const value = control.value;
|
---|
485 | return regex.test(value) ? null :
|
---|
486 | { 'pattern': { 'requiredPattern': regexStr, 'actualValue': value } };
|
---|
487 | };
|
---|
488 | }
|
---|
489 | /**
|
---|
490 | * Function that has `ValidatorFn` shape, but performs no operation.
|
---|
491 | */
|
---|
492 | export function nullValidator(control) {
|
---|
493 | return null;
|
---|
494 | }
|
---|
495 | function isPresent(o) {
|
---|
496 | return o != null;
|
---|
497 | }
|
---|
498 | export function toObservable(r) {
|
---|
499 | const obs = isPromise(r) ? from(r) : r;
|
---|
500 | if (!(isObservable(obs)) && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
---|
501 | throw new Error(`Expected validator to return Promise or Observable.`);
|
---|
502 | }
|
---|
503 | return obs;
|
---|
504 | }
|
---|
505 | function mergeErrors(arrayOfErrors) {
|
---|
506 | let res = {};
|
---|
507 | // Not using Array.reduce here due to a Chrome 80 bug
|
---|
508 | // https://bugs.chromium.org/p/chromium/issues/detail?id=1049982
|
---|
509 | arrayOfErrors.forEach((errors) => {
|
---|
510 | res = errors != null ? Object.assign(Object.assign({}, res), errors) : res;
|
---|
511 | });
|
---|
512 | return Object.keys(res).length === 0 ? null : res;
|
---|
513 | }
|
---|
514 | function executeValidators(control, validators) {
|
---|
515 | return validators.map(validator => validator(control));
|
---|
516 | }
|
---|
517 | function isValidatorFn(validator) {
|
---|
518 | return !validator.validate;
|
---|
519 | }
|
---|
520 | /**
|
---|
521 | * Given the list of validators that may contain both functions as well as classes, return the list
|
---|
522 | * of validator functions (convert validator classes into validator functions). This is needed to
|
---|
523 | * have consistent structure in validators list before composing them.
|
---|
524 | *
|
---|
525 | * @param validators The set of validators that may contain validators both in plain function form
|
---|
526 | * as well as represented as a validator class.
|
---|
527 | */
|
---|
528 | export function normalizeValidators(validators) {
|
---|
529 | return validators.map(validator => {
|
---|
530 | return isValidatorFn(validator) ?
|
---|
531 | validator :
|
---|
532 | ((c) => validator.validate(c));
|
---|
533 | });
|
---|
534 | }
|
---|
535 | /**
|
---|
536 | * Merges synchronous validators into a single validator function.
|
---|
537 | * See `Validators.compose` for additional information.
|
---|
538 | */
|
---|
539 | function compose(validators) {
|
---|
540 | if (!validators)
|
---|
541 | return null;
|
---|
542 | const presentValidators = validators.filter(isPresent);
|
---|
543 | if (presentValidators.length == 0)
|
---|
544 | return null;
|
---|
545 | return function (control) {
|
---|
546 | return mergeErrors(executeValidators(control, presentValidators));
|
---|
547 | };
|
---|
548 | }
|
---|
549 | /**
|
---|
550 | * Accepts a list of validators of different possible shapes (`Validator` and `ValidatorFn`),
|
---|
551 | * normalizes the list (converts everything to `ValidatorFn`) and merges them into a single
|
---|
552 | * validator function.
|
---|
553 | */
|
---|
554 | export function composeValidators(validators) {
|
---|
555 | return validators != null ? compose(normalizeValidators(validators)) : null;
|
---|
556 | }
|
---|
557 | /**
|
---|
558 | * Merges asynchronous validators into a single validator function.
|
---|
559 | * See `Validators.composeAsync` for additional information.
|
---|
560 | */
|
---|
561 | function composeAsync(validators) {
|
---|
562 | if (!validators)
|
---|
563 | return null;
|
---|
564 | const presentValidators = validators.filter(isPresent);
|
---|
565 | if (presentValidators.length == 0)
|
---|
566 | return null;
|
---|
567 | return function (control) {
|
---|
568 | const observables = executeValidators(control, presentValidators).map(toObservable);
|
---|
569 | return forkJoin(observables).pipe(map(mergeErrors));
|
---|
570 | };
|
---|
571 | }
|
---|
572 | /**
|
---|
573 | * Accepts a list of async validators of different possible shapes (`AsyncValidator` and
|
---|
574 | * `AsyncValidatorFn`), normalizes the list (converts everything to `AsyncValidatorFn`) and merges
|
---|
575 | * them into a single validator function.
|
---|
576 | */
|
---|
577 | export function composeAsyncValidators(validators) {
|
---|
578 | return validators != null ? composeAsync(normalizeValidators(validators)) :
|
---|
579 | null;
|
---|
580 | }
|
---|
581 | /**
|
---|
582 | * Merges raw control validators with a given directive validator and returns the combined list of
|
---|
583 | * validators as an array.
|
---|
584 | */
|
---|
585 | export function mergeValidators(controlValidators, dirValidator) {
|
---|
586 | if (controlValidators === null)
|
---|
587 | return [dirValidator];
|
---|
588 | return Array.isArray(controlValidators) ? [...controlValidators, dirValidator] :
|
---|
589 | [controlValidators, dirValidator];
|
---|
590 | }
|
---|
591 | /**
|
---|
592 | * Retrieves the list of raw synchronous validators attached to a given control.
|
---|
593 | */
|
---|
594 | export function getControlValidators(control) {
|
---|
595 | return control._rawValidators;
|
---|
596 | }
|
---|
597 | /**
|
---|
598 | * Retrieves the list of raw asynchronous validators attached to a given control.
|
---|
599 | */
|
---|
600 | export function getControlAsyncValidators(control) {
|
---|
601 | return control._rawAsyncValidators;
|
---|
602 | }
|
---|
603 | /**
|
---|
604 | * Accepts a singleton validator, an array, or null, and returns an array type with the provided
|
---|
605 | * validators.
|
---|
606 | *
|
---|
607 | * @param validators A validator, validators, or null.
|
---|
608 | * @returns A validators array.
|
---|
609 | */
|
---|
610 | export function makeValidatorsArray(validators) {
|
---|
611 | if (!validators)
|
---|
612 | return [];
|
---|
613 | return Array.isArray(validators) ? validators : [validators];
|
---|
614 | }
|
---|
615 | /**
|
---|
616 | * Determines whether a validator or validators array has a given validator.
|
---|
617 | *
|
---|
618 | * @param validators The validator or validators to compare against.
|
---|
619 | * @param validator The validator to check.
|
---|
620 | * @returns Whether the validator is present.
|
---|
621 | */
|
---|
622 | export function hasValidator(validators, validator) {
|
---|
623 | return Array.isArray(validators) ? validators.includes(validator) : validators === validator;
|
---|
624 | }
|
---|
625 | /**
|
---|
626 | * Combines two arrays of validators into one. If duplicates are provided, only one will be added.
|
---|
627 | *
|
---|
628 | * @param validators The new validators.
|
---|
629 | * @param currentValidators The base array of currrent validators.
|
---|
630 | * @returns An array of validators.
|
---|
631 | */
|
---|
632 | export function addValidators(validators, currentValidators) {
|
---|
633 | const current = makeValidatorsArray(currentValidators);
|
---|
634 | const validatorsToAdd = makeValidatorsArray(validators);
|
---|
635 | validatorsToAdd.forEach((v) => {
|
---|
636 | // Note: if there are duplicate entries in the new validators array,
|
---|
637 | // only the first one would be added to the current list of validarors.
|
---|
638 | // Duplicate ones would be ignored since `hasValidator` would detect
|
---|
639 | // the presence of a validator function and we update the current list in place.
|
---|
640 | if (!hasValidator(current, v)) {
|
---|
641 | current.push(v);
|
---|
642 | }
|
---|
643 | });
|
---|
644 | return current;
|
---|
645 | }
|
---|
646 | export function removeValidators(validators, currentValidators) {
|
---|
647 | return makeValidatorsArray(currentValidators).filter(v => !hasValidator(validators, v));
|
---|
648 | }
|
---|
649 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9ycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4u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