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 { Injectable } from '@angular/core';
|
---|
9 | import { ReactiveFormsModule } from './form_providers';
|
---|
10 | import { FormArray, FormControl, FormGroup } from './model';
|
---|
11 | import * as i0 from "@angular/core";
|
---|
12 | import * as i1 from "./form_providers";
|
---|
13 | function isAbstractControlOptions(options) {
|
---|
14 | return options.asyncValidators !== undefined ||
|
---|
15 | options.validators !== undefined ||
|
---|
16 | options.updateOn !== undefined;
|
---|
17 | }
|
---|
18 | /**
|
---|
19 | * @description
|
---|
20 | * Creates an `AbstractControl` from a user-specified configuration.
|
---|
21 | *
|
---|
22 | * The `FormBuilder` provides syntactic sugar that shortens creating instances of a `FormControl`,
|
---|
23 | * `FormGroup`, or `FormArray`. It reduces the amount of boilerplate needed to build complex
|
---|
24 | * forms.
|
---|
25 | *
|
---|
26 | * @see [Reactive Forms Guide](/guide/reactive-forms)
|
---|
27 | *
|
---|
28 | * @publicApi
|
---|
29 | */
|
---|
30 | export class FormBuilder {
|
---|
31 | group(controlsConfig, options = null) {
|
---|
32 | const controls = this._reduceControls(controlsConfig);
|
---|
33 | let validators = null;
|
---|
34 | let asyncValidators = null;
|
---|
35 | let updateOn = undefined;
|
---|
36 | if (options != null) {
|
---|
37 | if (isAbstractControlOptions(options)) {
|
---|
38 | // `options` are `AbstractControlOptions`
|
---|
39 | validators = options.validators != null ? options.validators : null;
|
---|
40 | asyncValidators = options.asyncValidators != null ? options.asyncValidators : null;
|
---|
41 | updateOn = options.updateOn != null ? options.updateOn : undefined;
|
---|
42 | }
|
---|
43 | else {
|
---|
44 | // `options` are legacy form group options
|
---|
45 | validators = options['validator'] != null ? options['validator'] : null;
|
---|
46 | asyncValidators = options['asyncValidator'] != null ? options['asyncValidator'] : null;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | return new FormGroup(controls, { asyncValidators, updateOn, validators });
|
---|
50 | }
|
---|
51 | /**
|
---|
52 | * @description
|
---|
53 | * Construct a new `FormControl` with the given state, validators and options.
|
---|
54 | *
|
---|
55 | * @param formState Initializes the control with an initial state value, or
|
---|
56 | * with an object that contains both a value and a disabled status.
|
---|
57 | *
|
---|
58 | * @param validatorOrOpts A synchronous validator function, or an array of
|
---|
59 | * such functions, or an `AbstractControlOptions` object that contains
|
---|
60 | * validation functions and a validation trigger.
|
---|
61 | *
|
---|
62 | * @param asyncValidator A single async validator or array of async validator
|
---|
63 | * functions.
|
---|
64 | *
|
---|
65 | * @usageNotes
|
---|
66 | *
|
---|
67 | * ### Initialize a control as disabled
|
---|
68 | *
|
---|
69 | * The following example returns a control with an initial value in a disabled state.
|
---|
70 | *
|
---|
71 | * <code-example path="forms/ts/formBuilder/form_builder_example.ts" region="disabled-control">
|
---|
72 | * </code-example>
|
---|
73 | */
|
---|
74 | control(formState, validatorOrOpts, asyncValidator) {
|
---|
75 | return new FormControl(formState, validatorOrOpts, asyncValidator);
|
---|
76 | }
|
---|
77 | /**
|
---|
78 | * Constructs a new `FormArray` from the given array of configurations,
|
---|
79 | * validators and options.
|
---|
80 | *
|
---|
81 | * @param controlsConfig An array of child controls or control configs. Each
|
---|
82 | * child control is given an index when it is registered.
|
---|
83 | *
|
---|
84 | * @param validatorOrOpts A synchronous validator function, or an array of
|
---|
85 | * such functions, or an `AbstractControlOptions` object that contains
|
---|
86 | * validation functions and a validation trigger.
|
---|
87 | *
|
---|
88 | * @param asyncValidator A single async validator or array of async validator
|
---|
89 | * functions.
|
---|
90 | */
|
---|
91 | array(controlsConfig, validatorOrOpts, asyncValidator) {
|
---|
92 | const controls = controlsConfig.map(c => this._createControl(c));
|
---|
93 | return new FormArray(controls, validatorOrOpts, asyncValidator);
|
---|
94 | }
|
---|
95 | /** @internal */
|
---|
96 | _reduceControls(controlsConfig) {
|
---|
97 | const controls = {};
|
---|
98 | Object.keys(controlsConfig).forEach(controlName => {
|
---|
99 | controls[controlName] = this._createControl(controlsConfig[controlName]);
|
---|
100 | });
|
---|
101 | return controls;
|
---|
102 | }
|
---|
103 | /** @internal */
|
---|
104 | _createControl(controlConfig) {
|
---|
105 | if (controlConfig instanceof FormControl || controlConfig instanceof FormGroup ||
|
---|
106 | controlConfig instanceof FormArray) {
|
---|
107 | return controlConfig;
|
---|
108 | }
|
---|
109 | else if (Array.isArray(controlConfig)) {
|
---|
110 | const value = controlConfig[0];
|
---|
111 | const validator = controlConfig.length > 1 ? controlConfig[1] : null;
|
---|
112 | const asyncValidator = controlConfig.length > 2 ? controlConfig[2] : null;
|
---|
113 | return this.control(value, validator, asyncValidator);
|
---|
114 | }
|
---|
115 | else {
|
---|
116 | return this.control(controlConfig);
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 | FormBuilder.ɵprov = i0.ɵɵdefineInjectable({ factory: function FormBuilder_Factory() { return new FormBuilder(); }, token: FormBuilder, providedIn: i1.ReactiveFormsModule });
|
---|
121 | FormBuilder.decorators = [
|
---|
122 | { type: Injectable, args: [{ providedIn: ReactiveFormsModule },] }
|
---|
123 | ];
|
---|
124 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybV9idWlsZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvZm9ybXMvc3JjL2Zvcm1fYnVpbGRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsVUFBVSxFQUFDLE1BQU0sZUFBZSxDQUFDO0FBR3pDLE9BQU8sRUFBQyxtQkFBbUIsRUFBQyxNQUFNLGtCQUFrQixDQUFDO0FBQ3JELE9BQU8sRUFBMEMsU0FBUyxFQUFFLFdBQVcsRUFBRSxTQUFTLEVBQVksTUFBTSxTQUFT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