@angular/forms 21.2.0-next.1 → 21.2.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/{_structure-chunk.mjs → _validation_errors-chunk.mjs} +138 -43
- package/fesm2022/_validation_errors-chunk.mjs.map +1 -0
- package/fesm2022/forms.mjs +170 -189
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +386 -47
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +683 -238
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +4 -4
- package/resources/code-examples.db +0 -0
- package/types/_structure-chunk.d.ts +642 -1406
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +131 -8
- package/types/signals.d.ts +107 -48
- package/fesm2022/_structure-chunk.mjs.map +0 -1
|
@@ -1,185 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.2.0-next.
|
|
2
|
+
* @license Angular v21.2.0-next.3
|
|
3
3
|
* (c) 2010-2026 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as i0 from '@angular/core';
|
|
8
|
-
import {
|
|
8
|
+
import { WritableSignal, Signal, InjectionToken, Injector, Provider } from '@angular/core';
|
|
9
9
|
import * as _angular_forms from '@angular/forms';
|
|
10
|
-
import { AbstractControl,
|
|
10
|
+
import { AbstractControl, ValidationErrors, FormControlStatus, ControlValueAccessor, ValidatorFn } from '@angular/forms';
|
|
11
11
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* This value is combined via a reduce operation defined by the particular key,
|
|
17
|
-
* since multiple rules in the schema might set values for it.
|
|
18
|
-
*
|
|
19
|
-
* @param path The target path to set the metadata for.
|
|
20
|
-
* @param key The metadata key
|
|
21
|
-
* @param logic A function that receives the `FieldContext` and returns a value for the metadata.
|
|
22
|
-
* @template TValue The type of value stored in the field the logic is bound to.
|
|
23
|
-
* @template TKey The type of metadata key.
|
|
24
|
-
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
25
|
-
*
|
|
26
|
-
* @category logic
|
|
27
|
-
* @experimental 21.0.0
|
|
28
|
-
*/
|
|
29
|
-
declare function metadata<TValue, TKey extends MetadataKey<any, any, any>, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, key: TKey, logic: NoInfer<LogicFn<TValue, MetadataSetterType<TKey>, TPathKind>>): TKey;
|
|
30
|
-
/**
|
|
31
|
-
* A reducer that determines the accumulated value for a metadata key by reducing the individual
|
|
32
|
-
* values contributed from `metadata()` rules.
|
|
33
|
-
*
|
|
34
|
-
* @template TAcc The accumulated type of the reduce operation.
|
|
35
|
-
* @template TItem The type of the individual items that are reduced over.
|
|
36
|
-
* @experimental 21.0.2
|
|
14
|
+
* Symbol used to retain generic type information when it would otherwise be lost.
|
|
37
15
|
*/
|
|
38
|
-
|
|
39
|
-
/** The reduce function. */
|
|
40
|
-
reduce: (acc: TAcc, item: TItem) => TAcc;
|
|
41
|
-
/** Gets the initial accumulated value. */
|
|
42
|
-
getInitial: () => TAcc;
|
|
43
|
-
}
|
|
44
|
-
declare const MetadataReducer: {
|
|
45
|
-
/** Creates a reducer that accumulates a list of its individual item values. */
|
|
46
|
-
readonly list: <TItem>() => MetadataReducer<TItem[], TItem | undefined>;
|
|
47
|
-
/** Creates a reducer that accumulates the min of its individual item values. */
|
|
48
|
-
readonly min: () => MetadataReducer<number | undefined, number | undefined>;
|
|
49
|
-
/** Creates a reducer that accumulates a the max of its individual item values. */
|
|
50
|
-
readonly max: () => MetadataReducer<number | undefined, number | undefined>;
|
|
51
|
-
/** Creates a reducer that logically or's its accumulated value with each individual item value. */
|
|
52
|
-
readonly or: () => MetadataReducer<boolean, boolean>;
|
|
53
|
-
/** Creates a reducer that logically and's its accumulated value with each individual item value. */
|
|
54
|
-
readonly and: () => MetadataReducer<boolean, boolean>;
|
|
55
|
-
/** Creates a reducer that always takes the next individual item value as the accumulated value. */
|
|
56
|
-
readonly override: typeof override;
|
|
57
|
-
};
|
|
58
|
-
declare function override<T>(): MetadataReducer<T | undefined, T>;
|
|
59
|
-
declare function override<T>(getInitial: () => T): MetadataReducer<T, T>;
|
|
16
|
+
declare const ɵɵTYPE: unique symbol;
|
|
60
17
|
/**
|
|
61
|
-
*
|
|
62
|
-
* function. A value can be contributed to the aggregated value for a field using an
|
|
63
|
-
* `metadata` rule in the schema. There may be multiple rules in a schema that contribute
|
|
64
|
-
* values to the same `MetadataKey` of the same field.
|
|
65
|
-
*
|
|
66
|
-
* @template TRead The type read from the `FieldState` for this key
|
|
67
|
-
* @template TWrite The type written to this key using the `metadata()` rule
|
|
68
|
-
* @template TAcc The type of the reducer's accumulated value.
|
|
18
|
+
* Options that can be specified when submitting a form.
|
|
69
19
|
*
|
|
70
|
-
* @experimental 21.
|
|
20
|
+
* @experimental 21.2.0
|
|
71
21
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
22
|
+
interface FormSubmitOptions<TRootModel, TSubmittedModel> {
|
|
23
|
+
/**
|
|
24
|
+
* Function to run when submitting the form data (when form is valid).
|
|
25
|
+
*
|
|
26
|
+
* @param field The contextually relevant field for this action function (the root field when
|
|
27
|
+
* specified during form creation, and the submitted field when specified as part of the
|
|
28
|
+
* `submit()` call)
|
|
29
|
+
* @param detail An object containing the root field of the submitted form as well as the
|
|
30
|
+
* submitted field itself
|
|
31
|
+
*/
|
|
32
|
+
action: (field: FieldTree<TRootModel & TSubmittedModel>, detail: {
|
|
33
|
+
root: FieldTree<TRootModel>;
|
|
34
|
+
submitted: FieldTree<TSubmittedModel>;
|
|
35
|
+
}) => Promise<TreeValidationResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Function to run when attempting to submit the form data but validation is failing.
|
|
38
|
+
*
|
|
39
|
+
* @param field The contextually relevant field for this onInvalid function (the root field when
|
|
40
|
+
* specified during form creation, and the submitted field when specified as part of the
|
|
41
|
+
* `submit()` call)
|
|
42
|
+
* @param detail An object containing the root field of the submitted form as well as the
|
|
43
|
+
* submitted field itself
|
|
44
|
+
*/
|
|
45
|
+
onInvalid?: (field: FieldTree<TRootModel & TSubmittedModel>, detail: {
|
|
46
|
+
root: FieldTree<TRootModel>;
|
|
47
|
+
submitted: FieldTree<TSubmittedModel>;
|
|
48
|
+
}) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Whether to ignore any of the validators when submitting:
|
|
51
|
+
* - 'pending': Will submit if there are no invalid validators, pending validators do not block submission (default)
|
|
52
|
+
* - 'none': Will not submit unless all validators are passing, pending validators block submission
|
|
53
|
+
* - 'ignore': Will always submit regardless of invalid or pending validators
|
|
54
|
+
*/
|
|
55
|
+
ignoreValidators?: 'pending' | 'none' | 'all';
|
|
78
56
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Extracts the the type that can be set into the given metadata key type using the `metadata()` rule.
|
|
81
|
-
*
|
|
82
|
-
* @template TKey The `MetadataKey` type
|
|
83
|
-
*
|
|
84
|
-
* @experimental 21.0.0
|
|
85
|
-
*/
|
|
86
|
-
type MetadataSetterType<TKey> = TKey extends MetadataKey<any, infer TWrite, any> ? TWrite : never;
|
|
87
|
-
/**
|
|
88
|
-
* Creates a metadata key used to contain a computed value.
|
|
89
|
-
* The last value set on a given field tree node overrides any previously set values.
|
|
90
|
-
*
|
|
91
|
-
* @template TWrite The type written to this key using the `metadata()` rule
|
|
92
|
-
*
|
|
93
|
-
* @experimental 21.0.0
|
|
94
|
-
*/
|
|
95
|
-
declare function createMetadataKey<TWrite>(): MetadataKey<Signal<TWrite | undefined>, TWrite, TWrite | undefined>;
|
|
96
|
-
/**
|
|
97
|
-
* Creates a metadata key used to contain a computed value.
|
|
98
|
-
*
|
|
99
|
-
* @param reducer The reducer used to combine individually set values into the final computed value.
|
|
100
|
-
* @template TWrite The type written to this key using the `metadata()` rule
|
|
101
|
-
* @template TAcc The type of the reducer's accumulated value.
|
|
102
|
-
*
|
|
103
|
-
* @experimental 21.0.0
|
|
104
|
-
*/
|
|
105
|
-
declare function createMetadataKey<TWrite, TAcc>(reducer: MetadataReducer<TAcc, TWrite>): MetadataKey<Signal<TAcc>, TWrite, TAcc>;
|
|
106
|
-
/**
|
|
107
|
-
* Creates a metadata key that exposes a managed value based on the accumulated result of the values
|
|
108
|
-
* written to the key. The accumulated value takes the last value set on a given field tree node,
|
|
109
|
-
* overriding any previously set values.
|
|
110
|
-
*
|
|
111
|
-
* @param create A function that receives a signal of the accumulated value and returns the managed
|
|
112
|
-
* value based on it. This function runs during the construction of the `FieldTree` node,
|
|
113
|
-
* and runs in the injection context of that node.
|
|
114
|
-
* @template TRead The type read from the `FieldState` for this key
|
|
115
|
-
* @template TWrite The type written to this key using the `metadata()` rule
|
|
116
|
-
*
|
|
117
|
-
* @experimental 21.0.0
|
|
118
|
-
*/
|
|
119
|
-
declare function createManagedMetadataKey<TRead, TWrite>(create: (s: Signal<TWrite | undefined>) => TRead): MetadataKey<TRead, TWrite, TWrite | undefined>;
|
|
120
|
-
/**
|
|
121
|
-
* Creates a metadata key that exposes a managed value based on the accumulated result of the values
|
|
122
|
-
* written to the key.
|
|
123
|
-
*
|
|
124
|
-
* @param create A function that receives a signal of the accumulated value and returns the managed
|
|
125
|
-
* value based on it. This function runs during the construction of the `FieldTree` node,
|
|
126
|
-
* and runs in the injection context of that node.
|
|
127
|
-
* @param reducer The reducer used to combine individual value written to the key,
|
|
128
|
-
* this will determine the accumulated value that the create function receives.
|
|
129
|
-
* @template TRead The type read from the `FieldState` for this key
|
|
130
|
-
* @template TWrite The type written to this key using the `metadata()` rule
|
|
131
|
-
* @template TAcc The type of the reducer's accumulated value.
|
|
132
|
-
*
|
|
133
|
-
* @experimental 21.0.0
|
|
134
|
-
*/
|
|
135
|
-
declare function createManagedMetadataKey<TRead, TWrite, TAcc>(create: (s: Signal<TAcc>) => TRead, reducer: MetadataReducer<TAcc, TWrite>): MetadataKey<TRead, TWrite, TAcc>;
|
|
136
|
-
/**
|
|
137
|
-
* A {@link MetadataKey} representing whether the field is required.
|
|
138
|
-
*
|
|
139
|
-
* @category validation
|
|
140
|
-
* @experimental 21.0.0
|
|
141
|
-
*/
|
|
142
|
-
declare const REQUIRED: MetadataKey<Signal<boolean>, boolean, boolean>;
|
|
143
|
-
/**
|
|
144
|
-
* A {@link MetadataKey} representing the min value of the field.
|
|
145
|
-
*
|
|
146
|
-
* @category validation
|
|
147
|
-
* @experimental 21.0.0
|
|
148
|
-
*/
|
|
149
|
-
declare const MIN: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
150
|
-
/**
|
|
151
|
-
* A {@link MetadataKey} representing the max value of the field.
|
|
152
|
-
*
|
|
153
|
-
* @category validation
|
|
154
|
-
* @experimental 21.0.0
|
|
155
|
-
*/
|
|
156
|
-
declare const MAX: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
157
|
-
/**
|
|
158
|
-
* A {@link MetadataKey} representing the min length of the field.
|
|
159
|
-
*
|
|
160
|
-
* @category validation
|
|
161
|
-
* @experimental 21.0.0
|
|
162
|
-
*/
|
|
163
|
-
declare const MIN_LENGTH: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
164
|
-
/**
|
|
165
|
-
* A {@link MetadataKey} representing the max length of the field.
|
|
166
|
-
*
|
|
167
|
-
* @category validation
|
|
168
|
-
* @experimental 21.0.0
|
|
169
|
-
*/
|
|
170
|
-
declare const MAX_LENGTH: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
171
|
-
/**
|
|
172
|
-
* A {@link MetadataKey} representing the patterns the field must match.
|
|
173
|
-
*
|
|
174
|
-
* @category validation
|
|
175
|
-
* @experimental 21.0.0
|
|
176
|
-
*/
|
|
177
|
-
declare const PATTERN: MetadataKey<Signal<RegExp[]>, RegExp | undefined, RegExp[]>;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Symbol used to retain generic type information when it would otherwise be lost.
|
|
181
|
-
*/
|
|
182
|
-
declare const ɵɵTYPE: unique symbol;
|
|
183
57
|
/**
|
|
184
58
|
* A type that represents either a single value of type `T` or a readonly array of `T`.
|
|
185
59
|
* @template T The type of the value(s).
|
|
@@ -333,7 +207,68 @@ type MaybeFieldTree<TModel, TKey extends string | number = string | number> = (T
|
|
|
333
207
|
* @category structure
|
|
334
208
|
* @experimental 21.0.0
|
|
335
209
|
*/
|
|
336
|
-
interface FieldState<TValue, TKey extends string | number = string | number>
|
|
210
|
+
interface FieldState<TValue, TKey extends string | number = string | number> {
|
|
211
|
+
/**
|
|
212
|
+
* The {@link FieldTree} associated with this field state.
|
|
213
|
+
*/
|
|
214
|
+
readonly fieldTree: FieldTree<unknown, TKey>;
|
|
215
|
+
/**
|
|
216
|
+
* A writable signal containing the value for this field.
|
|
217
|
+
*
|
|
218
|
+
* Updating this signal will update the data model that the field is bound to.
|
|
219
|
+
*
|
|
220
|
+
* While updates from the UI control are eventually reflected here, they may be delayed if
|
|
221
|
+
* debounced.
|
|
222
|
+
*/
|
|
223
|
+
readonly value: WritableSignal<TValue>;
|
|
224
|
+
/**
|
|
225
|
+
* A signal indicating whether the field is currently disabled.
|
|
226
|
+
*/
|
|
227
|
+
readonly disabled: Signal<boolean>;
|
|
228
|
+
/**
|
|
229
|
+
* A signal indicating the field's maximum value, if applicable.
|
|
230
|
+
*
|
|
231
|
+
* Applies to `<input>` with a numeric or date `type` attribute and custom controls.
|
|
232
|
+
*/
|
|
233
|
+
readonly max?: Signal<number | undefined>;
|
|
234
|
+
/**
|
|
235
|
+
* A signal indicating the field's maximum string length, if applicable.
|
|
236
|
+
*
|
|
237
|
+
* Applies to `<input>`, `<textarea>`, and custom controls.
|
|
238
|
+
*/
|
|
239
|
+
readonly maxLength?: Signal<number | undefined>;
|
|
240
|
+
/**
|
|
241
|
+
* A signal indicating the field's minimum value, if applicable.
|
|
242
|
+
*
|
|
243
|
+
* Applies to `<input>` with a numeric or date `type` attribute and custom controls.
|
|
244
|
+
*/
|
|
245
|
+
readonly min?: Signal<number | undefined>;
|
|
246
|
+
/**
|
|
247
|
+
* A signal indicating the field's minimum string length, if applicable.
|
|
248
|
+
*
|
|
249
|
+
* Applies to `<input>`, `<textarea>`, and custom controls.
|
|
250
|
+
*/
|
|
251
|
+
readonly minLength?: Signal<number | undefined>;
|
|
252
|
+
/**
|
|
253
|
+
* A signal of a unique name for the field, by default based on the name of its parent field.
|
|
254
|
+
*/
|
|
255
|
+
readonly name: Signal<string>;
|
|
256
|
+
/**
|
|
257
|
+
* A signal indicating the patterns the field must match.
|
|
258
|
+
*/
|
|
259
|
+
readonly pattern: Signal<readonly RegExp[]>;
|
|
260
|
+
/**
|
|
261
|
+
* A signal indicating whether the field is currently readonly.
|
|
262
|
+
*/
|
|
263
|
+
readonly readonly: Signal<boolean>;
|
|
264
|
+
/**
|
|
265
|
+
* A signal indicating whether the field is required.
|
|
266
|
+
*/
|
|
267
|
+
readonly required: Signal<boolean>;
|
|
268
|
+
/**
|
|
269
|
+
* A signal indicating whether the field has been touched by the user.
|
|
270
|
+
*/
|
|
271
|
+
readonly touched: Signal<boolean>;
|
|
337
272
|
/**
|
|
338
273
|
* A signal indicating whether field value has been changed by user.
|
|
339
274
|
*/
|
|
@@ -398,6 +333,22 @@ interface FieldState<TValue, TKey extends string | number = string | number> ext
|
|
|
398
333
|
* The {@link FormField} directives that bind this field to a UI control.
|
|
399
334
|
*/
|
|
400
335
|
readonly formFieldBindings: Signal<readonly FormField<unknown>[]>;
|
|
336
|
+
/**
|
|
337
|
+
* A signal containing the value of the control to which this field is bound.
|
|
338
|
+
*
|
|
339
|
+
* This differs from {@link value} in that it's not subject to debouncing, and thus is used to
|
|
340
|
+
* buffer debounced updates from the control to the field. This will also not take into account
|
|
341
|
+
* the {@link controlValue} of children.
|
|
342
|
+
*/
|
|
343
|
+
readonly controlValue: WritableSignal<TValue>;
|
|
344
|
+
/**
|
|
345
|
+
* Sets the dirty status of the field to `true`.
|
|
346
|
+
*/
|
|
347
|
+
markAsDirty(): void;
|
|
348
|
+
/**
|
|
349
|
+
* Sets the touched status of the field to `true`.
|
|
350
|
+
*/
|
|
351
|
+
markAsTouched(): void;
|
|
401
352
|
/**
|
|
402
353
|
* Reads a metadata value from the field.
|
|
403
354
|
* @param key The metadata key to read.
|
|
@@ -687,46 +638,296 @@ type ItemType<T extends Object> = T extends ReadonlyArray<any> ? T[number] : T[k
|
|
|
687
638
|
type Debouncer<TValue, TPathKind extends PathKind = PathKind.Root> = (context: FieldContext<TValue, TPathKind>, abortSignal: AbortSignal) => Promise<void> | void;
|
|
688
639
|
|
|
689
640
|
/**
|
|
690
|
-
*
|
|
641
|
+
* Sets a value for the {@link MetadataKey} for this field.
|
|
642
|
+
*
|
|
643
|
+
* This value is combined via a reduce operation defined by the particular key,
|
|
644
|
+
* since multiple rules in the schema might set values for it.
|
|
645
|
+
*
|
|
646
|
+
* @param path The target path to set the metadata for.
|
|
647
|
+
* @param key The metadata key
|
|
648
|
+
* @param logic A function that receives the `FieldContext` and returns a value for the metadata.
|
|
649
|
+
* @template TValue The type of value stored in the field the logic is bound to.
|
|
650
|
+
* @template TKey The type of metadata key.
|
|
651
|
+
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
652
|
+
*
|
|
653
|
+
* @category logic
|
|
654
|
+
* @experimental 21.0.0
|
|
691
655
|
*/
|
|
692
|
-
|
|
656
|
+
declare function metadata<TValue, TKey extends MetadataKey<any, any, any>, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, key: TKey, logic: NoInfer<LogicFn<TValue, MetadataSetterType<TKey>, TPathKind>>): TKey;
|
|
693
657
|
/**
|
|
694
|
-
* A
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
658
|
+
* A reducer that determines the accumulated value for a metadata key by reducing the individual
|
|
659
|
+
* values contributed from `metadata()` rules.
|
|
660
|
+
*
|
|
661
|
+
* @template TAcc The accumulated type of the reduce operation.
|
|
662
|
+
* @template TItem The type of the individual items that are reduced over.
|
|
663
|
+
* @experimental 21.0.2
|
|
699
664
|
*/
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
665
|
+
interface MetadataReducer<TAcc, TItem> {
|
|
666
|
+
/** The reduce function. */
|
|
667
|
+
reduce: (acc: TAcc, item: TItem) => TAcc;
|
|
668
|
+
/** Gets the initial accumulated value. */
|
|
669
|
+
getInitial: () => TAcc;
|
|
670
|
+
}
|
|
671
|
+
declare const MetadataReducer: {
|
|
672
|
+
/** Creates a reducer that accumulates a list of its individual item values. */
|
|
673
|
+
readonly list: <TItem>() => MetadataReducer<TItem[], TItem | undefined>;
|
|
674
|
+
/** Creates a reducer that accumulates the min of its individual item values. */
|
|
675
|
+
readonly min: () => MetadataReducer<number | undefined, number | undefined>;
|
|
676
|
+
/** Creates a reducer that accumulates a the max of its individual item values. */
|
|
677
|
+
readonly max: () => MetadataReducer<number | undefined, number | undefined>;
|
|
678
|
+
/** Creates a reducer that logically or's its accumulated value with each individual item value. */
|
|
679
|
+
readonly or: () => MetadataReducer<boolean, boolean>;
|
|
680
|
+
/** Creates a reducer that logically and's its accumulated value with each individual item value. */
|
|
681
|
+
readonly and: () => MetadataReducer<boolean, boolean>;
|
|
682
|
+
/** Creates a reducer that always takes the next individual item value as the accumulated value. */
|
|
683
|
+
readonly override: typeof override;
|
|
684
|
+
};
|
|
685
|
+
declare function override<T>(): MetadataReducer<T | undefined, T>;
|
|
686
|
+
declare function override<T>(getInitial: () => T): MetadataReducer<T, T>;
|
|
687
|
+
/**
|
|
688
|
+
* Represents metadata that is aggregated from multiple parts according to the key's reducer
|
|
689
|
+
* function. A value can be contributed to the aggregated value for a field using an
|
|
690
|
+
* `metadata` rule in the schema. There may be multiple rules in a schema that contribute
|
|
691
|
+
* values to the same `MetadataKey` of the same field.
|
|
692
|
+
*
|
|
693
|
+
* @template TRead The type read from the `FieldState` for this key
|
|
694
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
695
|
+
* @template TAcc The type of the reducer's accumulated value.
|
|
696
|
+
*
|
|
697
|
+
* @experimental 21.0.0
|
|
698
|
+
*/
|
|
699
|
+
declare class MetadataKey<TRead, TWrite, TAcc> {
|
|
700
|
+
readonly reducer: MetadataReducer<TAcc, TWrite>;
|
|
701
|
+
readonly create: ((s: Signal<TAcc>) => TRead) | undefined;
|
|
702
|
+
private brand;
|
|
703
|
+
/** Use {@link reducedMetadataKey}. */
|
|
704
|
+
protected constructor(reducer: MetadataReducer<TAcc, TWrite>, create: ((s: Signal<TAcc>) => TRead) | undefined);
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Extracts the the type that can be set into the given metadata key type using the `metadata()` rule.
|
|
708
|
+
*
|
|
709
|
+
* @template TKey The `MetadataKey` type
|
|
710
|
+
*
|
|
711
|
+
* @experimental 21.0.0
|
|
712
|
+
*/
|
|
713
|
+
type MetadataSetterType<TKey> = TKey extends MetadataKey<any, infer TWrite, any> ? TWrite : never;
|
|
714
|
+
/**
|
|
715
|
+
* Creates a metadata key used to contain a computed value.
|
|
716
|
+
* The last value set on a given field tree node overrides any previously set values.
|
|
717
|
+
*
|
|
718
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
719
|
+
*
|
|
720
|
+
* @experimental 21.0.0
|
|
721
|
+
*/
|
|
722
|
+
declare function createMetadataKey<TWrite>(): MetadataKey<Signal<TWrite | undefined>, TWrite, TWrite | undefined>;
|
|
723
|
+
/**
|
|
724
|
+
* Creates a metadata key used to contain a computed value.
|
|
725
|
+
*
|
|
726
|
+
* @param reducer The reducer used to combine individually set values into the final computed value.
|
|
727
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
728
|
+
* @template TAcc The type of the reducer's accumulated value.
|
|
729
|
+
*
|
|
730
|
+
* @experimental 21.0.0
|
|
731
|
+
*/
|
|
732
|
+
declare function createMetadataKey<TWrite, TAcc>(reducer: MetadataReducer<TAcc, TWrite>): MetadataKey<Signal<TAcc>, TWrite, TAcc>;
|
|
733
|
+
/**
|
|
734
|
+
* Creates a metadata key that exposes a managed value based on the accumulated result of the values
|
|
735
|
+
* written to the key. The accumulated value takes the last value set on a given field tree node,
|
|
736
|
+
* overriding any previously set values.
|
|
737
|
+
*
|
|
738
|
+
* @param create A function that receives a signal of the accumulated value and returns the managed
|
|
739
|
+
* value based on it. This function runs during the construction of the `FieldTree` node,
|
|
740
|
+
* and runs in the injection context of that node.
|
|
741
|
+
* @template TRead The type read from the `FieldState` for this key
|
|
742
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
743
|
+
*
|
|
744
|
+
* @experimental 21.0.0
|
|
745
|
+
*/
|
|
746
|
+
declare function createManagedMetadataKey<TRead, TWrite>(create: (s: Signal<TWrite | undefined>) => TRead): MetadataKey<TRead, TWrite, TWrite | undefined>;
|
|
747
|
+
/**
|
|
748
|
+
* Creates a metadata key that exposes a managed value based on the accumulated result of the values
|
|
749
|
+
* written to the key.
|
|
750
|
+
*
|
|
751
|
+
* @param create A function that receives a signal of the accumulated value and returns the managed
|
|
752
|
+
* value based on it. This function runs during the construction of the `FieldTree` node,
|
|
753
|
+
* and runs in the injection context of that node.
|
|
754
|
+
* @param reducer The reducer used to combine individual value written to the key,
|
|
755
|
+
* this will determine the accumulated value that the create function receives.
|
|
756
|
+
* @template TRead The type read from the `FieldState` for this key
|
|
757
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
758
|
+
* @template TAcc The type of the reducer's accumulated value.
|
|
759
|
+
*
|
|
760
|
+
* @experimental 21.0.0
|
|
761
|
+
*/
|
|
762
|
+
declare function createManagedMetadataKey<TRead, TWrite, TAcc>(create: (s: Signal<TAcc>) => TRead, reducer: MetadataReducer<TAcc, TWrite>): MetadataKey<TRead, TWrite, TAcc>;
|
|
763
|
+
/**
|
|
764
|
+
* A {@link MetadataKey} representing whether the field is required.
|
|
765
|
+
*
|
|
766
|
+
* @category validation
|
|
767
|
+
* @experimental 21.0.0
|
|
768
|
+
*/
|
|
769
|
+
declare const REQUIRED: MetadataKey<Signal<boolean>, boolean, boolean>;
|
|
770
|
+
/**
|
|
771
|
+
* A {@link MetadataKey} representing the min value of the field.
|
|
772
|
+
*
|
|
773
|
+
* @category validation
|
|
774
|
+
* @experimental 21.0.0
|
|
775
|
+
*/
|
|
776
|
+
declare const MIN: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
777
|
+
/**
|
|
778
|
+
* A {@link MetadataKey} representing the max value of the field.
|
|
779
|
+
*
|
|
780
|
+
* @category validation
|
|
781
|
+
* @experimental 21.0.0
|
|
782
|
+
*/
|
|
783
|
+
declare const MAX: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
784
|
+
/**
|
|
785
|
+
* A {@link MetadataKey} representing the min length of the field.
|
|
786
|
+
*
|
|
787
|
+
* @category validation
|
|
788
|
+
* @experimental 21.0.0
|
|
789
|
+
*/
|
|
790
|
+
declare const MIN_LENGTH: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
791
|
+
/**
|
|
792
|
+
* A {@link MetadataKey} representing the max length of the field.
|
|
793
|
+
*
|
|
794
|
+
* @category validation
|
|
795
|
+
* @experimental 21.0.0
|
|
796
|
+
*/
|
|
797
|
+
declare const MAX_LENGTH: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
798
|
+
/**
|
|
799
|
+
* A {@link MetadataKey} representing the patterns the field must match.
|
|
800
|
+
*
|
|
801
|
+
* @category validation
|
|
802
|
+
* @experimental 21.0.0
|
|
803
|
+
*/
|
|
804
|
+
declare const PATTERN: MetadataKey<Signal<RegExp[]>, RegExp | undefined, RegExp[]>;
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Utility type that removes a string index key when its value is `unknown`,
|
|
808
|
+
* i.e. `{[key: string]: unknown}`. It allows specific string keys to pass through, even if their
|
|
809
|
+
* value is `unknown`, e.g. `{key: unknown}`.
|
|
810
|
+
*
|
|
811
|
+
* @experimental 21.0.0
|
|
812
|
+
*/
|
|
813
|
+
type RemoveStringIndexUnknownKey<K, V> = string extends K ? unknown extends V ? never : K : K;
|
|
814
|
+
/**
|
|
815
|
+
* Utility type that recursively ignores unknown string index properties on the given object.
|
|
816
|
+
* We use this on the `TSchema` type in `validateStandardSchema` in order to accommodate Zod's
|
|
817
|
+
* `looseObject` which includes `{[key: string]: unknown}` as part of the type.
|
|
818
|
+
*
|
|
819
|
+
* @experimental 21.0.0
|
|
820
|
+
*/
|
|
821
|
+
type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
|
|
822
|
+
[K in keyof T as RemoveStringIndexUnknownKey<K, T[K]>]: IgnoreUnknownProperties<T[K]>;
|
|
823
|
+
} : T;
|
|
824
|
+
/**
|
|
825
|
+
* Validates a field using a `StandardSchemaV1` compatible validator (e.g. a Zod validator).
|
|
826
|
+
*
|
|
827
|
+
* See https://github.com/standard-schema/standard-schema for more about standard schema.
|
|
828
|
+
*
|
|
829
|
+
* @param path The `FieldPath` to the field to validate.
|
|
830
|
+
* @param schema The standard schema compatible validator to use for validation, or a LogicFn that returns the schema.
|
|
831
|
+
* @template TSchema The type validated by the schema. This may be either the full `TValue` type,
|
|
832
|
+
* or a partial of it.
|
|
833
|
+
* @template TValue The type of value stored in the field being validated.
|
|
834
|
+
*
|
|
835
|
+
* @see [Signal Form Schema Validation](guide/forms/signals/validation#integration-with-schema-validation-libraries)
|
|
836
|
+
* @category validation
|
|
837
|
+
* @experimental 21.0.0
|
|
838
|
+
*/
|
|
839
|
+
declare function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProperties<TSchema>>(path: SchemaPath<TModel> & SchemaPathTree<TModel>, schema: StandardSchemaV1<TSchema> | LogicFn<TModel, StandardSchemaV1<unknown> | undefined>): void;
|
|
840
|
+
/**
|
|
841
|
+
* Create a standard schema issue error associated with the target field
|
|
842
|
+
* @param issue The standard schema issue
|
|
843
|
+
* @param options The validation error options
|
|
844
|
+
*
|
|
845
|
+
* @category validation
|
|
846
|
+
* @experimental 21.0.0
|
|
847
|
+
*/
|
|
848
|
+
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options: WithFieldTree<ValidationErrorOptions>): StandardSchemaValidationError;
|
|
849
|
+
/**
|
|
850
|
+
* Create a standard schema issue error
|
|
851
|
+
* @param issue The standard schema issue
|
|
852
|
+
* @param options The optional validation error options
|
|
853
|
+
*
|
|
854
|
+
* @category validation
|
|
855
|
+
* @experimental 21.0.0
|
|
856
|
+
*/
|
|
857
|
+
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions): WithoutFieldTree<StandardSchemaValidationError>;
|
|
858
|
+
/**
|
|
859
|
+
* An error used to indicate an issue validating against a standard schema.
|
|
860
|
+
*
|
|
861
|
+
* @category validation
|
|
862
|
+
* @experimental 21.0.0
|
|
863
|
+
*/
|
|
864
|
+
declare class StandardSchemaValidationError extends BaseNgValidationError {
|
|
865
|
+
readonly issue: StandardSchemaV1.Issue;
|
|
866
|
+
readonly kind = "standardSchema";
|
|
867
|
+
constructor(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Represents a combination of `NgControl` and `AbstractControl`.
|
|
872
|
+
*
|
|
873
|
+
* Note: We have this separate interface, rather than implementing the relevant parts of the two
|
|
874
|
+
* controls with something like `InteropNgControl implements Pick<NgControl, ...>, Pick<AbstractControl, ...>`
|
|
875
|
+
* because it confuses the internal JS minifier which can cause collisions in field names.
|
|
876
|
+
*/
|
|
877
|
+
interface CombinedControl {
|
|
878
|
+
value: any;
|
|
879
|
+
valid: boolean;
|
|
880
|
+
invalid: boolean;
|
|
881
|
+
touched: boolean;
|
|
882
|
+
untouched: boolean;
|
|
883
|
+
disabled: boolean;
|
|
884
|
+
enabled: boolean;
|
|
885
|
+
errors: ValidationErrors | null;
|
|
886
|
+
pristine: boolean;
|
|
887
|
+
dirty: boolean;
|
|
888
|
+
status: FormControlStatus;
|
|
889
|
+
control: AbstractControl<any, any>;
|
|
890
|
+
valueAccessor: ControlValueAccessor | null;
|
|
891
|
+
hasValidator(validator: ValidatorFn): boolean;
|
|
892
|
+
updateValueAndValidity(): void;
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* A fake version of `NgControl` provided by the `Field` directive. This allows interoperability
|
|
896
|
+
* with a wider range of components designed to work with reactive forms, in particular ones that
|
|
897
|
+
* inject the `NgControl`. The interop control does not implement *all* properties and methods of
|
|
898
|
+
* the real `NgControl`, but does implement some of the most commonly used ones that have a clear
|
|
899
|
+
* equivalent in signal forms.
|
|
900
|
+
*/
|
|
901
|
+
declare class InteropNgControl implements CombinedControl {
|
|
902
|
+
protected field: () => FieldState<unknown>;
|
|
903
|
+
constructor(field: () => FieldState<unknown>);
|
|
904
|
+
readonly control: AbstractControl<any, any>;
|
|
905
|
+
get value(): any;
|
|
906
|
+
get valid(): boolean;
|
|
907
|
+
get invalid(): boolean;
|
|
908
|
+
get pending(): boolean | null;
|
|
909
|
+
get disabled(): boolean;
|
|
910
|
+
get enabled(): boolean;
|
|
911
|
+
get errors(): ValidationErrors | null;
|
|
912
|
+
get pristine(): boolean;
|
|
913
|
+
get dirty(): boolean;
|
|
914
|
+
get touched(): boolean;
|
|
915
|
+
get untouched(): boolean;
|
|
916
|
+
get status(): FormControlStatus;
|
|
917
|
+
valueAccessor: ControlValueAccessor | null;
|
|
918
|
+
hasValidator(validator: ValidatorFn): boolean;
|
|
919
|
+
updateValueAndValidity(): void;
|
|
719
920
|
}
|
|
720
921
|
|
|
721
|
-
|
|
922
|
+
declare const ɵNgFieldDirective: unique symbol;
|
|
923
|
+
interface FormFieldBindingOptions {
|
|
722
924
|
/**
|
|
723
925
|
* Focuses the binding.
|
|
724
926
|
*
|
|
725
927
|
* If not specified, Signal Forms will attempt to focus the host element of the `FormField` when
|
|
726
928
|
* asked to focus this binding.
|
|
727
929
|
*/
|
|
728
|
-
focus
|
|
729
|
-
readonly parseErrors?: Signal<ValidationError.WithoutFieldTree[]>;
|
|
930
|
+
readonly focus?: (focusOptions?: FocusOptions) => void;
|
|
730
931
|
}
|
|
731
932
|
/**
|
|
732
933
|
* Lightweight DI token provided by the {@link FormField} directive.
|
|
@@ -755,33 +956,64 @@ declare const FORM_FIELD: InjectionToken<FormField<unknown>>;
|
|
|
755
956
|
* @experimental 21.0.0
|
|
756
957
|
*/
|
|
757
958
|
declare class FormField<T> {
|
|
758
|
-
readonly element: HTMLElement;
|
|
759
|
-
readonly injector: Injector;
|
|
760
959
|
readonly fieldTree: i0.InputSignal<FieldTree<T>>;
|
|
960
|
+
/**
|
|
961
|
+
* `FieldState` for the currently bound field.
|
|
962
|
+
*/
|
|
761
963
|
readonly state: Signal<[T] extends [_angular_forms.AbstractControl<any, any, any>] ? CompatFieldState<T, string | number> : FieldState<T, string | number>>;
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
readonly
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
964
|
+
/**
|
|
965
|
+
* The node injector for the element this field binding.
|
|
966
|
+
*/
|
|
967
|
+
readonly injector: Injector;
|
|
968
|
+
/**
|
|
969
|
+
* The DOM element hosting this field binding.
|
|
970
|
+
*/
|
|
971
|
+
readonly element: HTMLElement;
|
|
972
|
+
private readonly elementIsNativeFormElement;
|
|
973
|
+
private readonly elementAcceptsNumericValues;
|
|
974
|
+
private readonly elementAcceptsTextualValues;
|
|
975
|
+
/**
|
|
976
|
+
* Current focus implementation, set by `registerAsBinding`.
|
|
977
|
+
*/
|
|
978
|
+
private focuser;
|
|
770
979
|
/** Any `ControlValueAccessor` instances provided on the host element. */
|
|
771
980
|
private readonly controlValueAccessors;
|
|
981
|
+
private readonly config;
|
|
982
|
+
private readonly parseErrorsSource;
|
|
772
983
|
/** A lazily instantiated fake `NgControl`. */
|
|
773
|
-
private
|
|
984
|
+
private _interopNgControl;
|
|
774
985
|
/** Lazily instantiates a fake `NgControl` for this form field. */
|
|
775
|
-
protected
|
|
986
|
+
protected get interopNgControl(): InteropNgControl;
|
|
987
|
+
/** Errors associated with this form field. */
|
|
988
|
+
readonly errors: Signal<ValidationError.WithFieldTree[]>;
|
|
989
|
+
/** Whether this `FormField` has been registered as a binding on its associated `FieldState`. */
|
|
990
|
+
private isFieldBinding;
|
|
991
|
+
/**
|
|
992
|
+
* Creates an `afterRenderEffect` that applies the configured class bindings to the host element
|
|
993
|
+
* if needed.
|
|
994
|
+
*/
|
|
995
|
+
private installClassBindingEffect;
|
|
996
|
+
/**
|
|
997
|
+
* Focuses this field binding.
|
|
998
|
+
*
|
|
999
|
+
* By default, this will focus the host DOM element. However, custom `FormUiControl`s can
|
|
1000
|
+
* implement custom focusing behavior.
|
|
1001
|
+
*/
|
|
1002
|
+
focus(options?: FocusOptions): void;
|
|
776
1003
|
/**
|
|
777
1004
|
* Registers this `FormField` as a binding on its associated `FieldState`.
|
|
778
1005
|
*
|
|
779
1006
|
* This method should be called at most once for a given `FormField`. A `FormField` placed on a
|
|
780
1007
|
* custom control (`FormUiControl`) automatically registers that custom control as a binding.
|
|
781
1008
|
*/
|
|
782
|
-
registerAsBinding(bindingOptions?: FormFieldBindingOptions
|
|
783
|
-
/**
|
|
784
|
-
|
|
1009
|
+
registerAsBinding(bindingOptions?: FormFieldBindingOptions): void;
|
|
1010
|
+
/**
|
|
1011
|
+
* The presence of this symbol tells the template type-checker that this directive is a control
|
|
1012
|
+
* directive and should be type-checked as such. We don't use the `ɵngControlCreate` method below
|
|
1013
|
+
* as it's marked internal and removed from the public API. A symbol is used instead to avoid
|
|
1014
|
+
* polluting the public API with the marker.
|
|
1015
|
+
*/
|
|
1016
|
+
readonly [ɵNgFieldDirective]: true;
|
|
785
1017
|
static ɵfac: i0.ɵɵFactoryDeclaration<FormField<any>, never>;
|
|
786
1018
|
static ɵdir: i0.ɵɵDirectiveDeclaration<FormField<any>, "[formField]", ["formField"], { "fieldTree": { "alias": "formField"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
787
1019
|
}
|
|
@@ -927,1222 +1159,225 @@ declare function patternError(pattern: RegExp, options: WithFieldTree<Validation
|
|
|
927
1159
|
* @param pattern The violated pattern
|
|
928
1160
|
* @param options The optional validation error options
|
|
929
1161
|
*
|
|
930
|
-
* @category validation
|
|
931
|
-
* @experimental 21.0.0
|
|
932
|
-
*/
|
|
933
|
-
declare function patternError(pattern: RegExp, options?: ValidationErrorOptions): WithoutFieldTree<PatternValidationError>;
|
|
934
|
-
/**
|
|
935
|
-
* Create an email format error associated with the target field
|
|
936
|
-
* @param options The validation error options
|
|
937
|
-
*
|
|
938
|
-
* @category validation
|
|
939
|
-
* @experimental 21.0.0
|
|
940
|
-
*/
|
|
941
|
-
declare function emailError(options: WithFieldTree<ValidationErrorOptions>): EmailValidationError;
|
|
942
|
-
/**
|
|
943
|
-
* Create an email format error
|
|
944
|
-
* @param options The optional validation error options
|
|
945
|
-
*
|
|
946
|
-
* @category validation
|
|
947
|
-
* @experimental 21.0.0
|
|
948
|
-
*/
|
|
949
|
-
declare function emailError(options?: ValidationErrorOptions): WithoutFieldTree<EmailValidationError>;
|
|
950
|
-
/**
|
|
951
|
-
* Create a standard schema issue error associated with the target field
|
|
952
|
-
* @param issue The standard schema issue
|
|
953
|
-
* @param options The validation error options
|
|
954
|
-
*
|
|
955
|
-
* @category validation
|
|
956
|
-
* @experimental 21.0.0
|
|
957
|
-
*/
|
|
958
|
-
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options: WithFieldTree<ValidationErrorOptions>): StandardSchemaValidationError;
|
|
959
|
-
/**
|
|
960
|
-
* Create a standard schema issue error
|
|
961
|
-
* @param issue The standard schema issue
|
|
962
|
-
* @param options The optional validation error options
|
|
963
|
-
*
|
|
964
|
-
* @category validation
|
|
965
|
-
* @experimental 21.0.0
|
|
966
|
-
*/
|
|
967
|
-
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions): WithoutFieldTree<StandardSchemaValidationError>;
|
|
968
|
-
/**
|
|
969
|
-
* Common interface for all validation errors.
|
|
970
|
-
*
|
|
971
|
-
* This can be returned from validators.
|
|
972
|
-
*
|
|
973
|
-
* It's also used by the creation functions to create an instance
|
|
974
|
-
* (e.g. `requiredError`, `minError`, etc.).
|
|
975
|
-
*
|
|
976
|
-
* @see [Signal Form Validation](guide/forms/signals/validation)
|
|
977
|
-
* @see [Signal Form Validation Errors](guide/forms/signals/validation#validation-errors)
|
|
978
|
-
* @category validation
|
|
979
|
-
* @experimental 21.0.0
|
|
980
|
-
*/
|
|
981
|
-
interface ValidationError {
|
|
982
|
-
/** Identifies the kind of error. */
|
|
983
|
-
readonly kind: string;
|
|
984
|
-
/** Human readable error message. */
|
|
985
|
-
readonly message?: string;
|
|
986
|
-
}
|
|
987
|
-
declare namespace ValidationError {
|
|
988
|
-
/**
|
|
989
|
-
* Validation error with an associated field tree.
|
|
990
|
-
*
|
|
991
|
-
* This is returned from field state, e.g., catField.errors() would be of a list of errors with
|
|
992
|
-
* `field: catField` bound to state.
|
|
993
|
-
*/
|
|
994
|
-
interface WithFieldTree extends ValidationError {
|
|
995
|
-
/** The field associated with this error. */
|
|
996
|
-
readonly fieldTree: FieldTree<unknown>;
|
|
997
|
-
readonly formField?: FormField<unknown>;
|
|
998
|
-
}
|
|
999
|
-
/** @deprecated Use `ValidationError.WithFieldTree` instead */
|
|
1000
|
-
type WithField = WithFieldTree;
|
|
1001
|
-
/**
|
|
1002
|
-
* Validation error with an associated field tree and specific form field binding.
|
|
1003
|
-
*/
|
|
1004
|
-
interface WithFormField extends WithFieldTree {
|
|
1005
|
-
readonly formField: FormField<unknown>;
|
|
1006
|
-
}
|
|
1007
|
-
/**
|
|
1008
|
-
* Validation error with optional field.
|
|
1009
|
-
*
|
|
1010
|
-
* This is generally used in places where the result might have a field.
|
|
1011
|
-
* e.g., as a result of a `validateTree`, or when handling form submission.
|
|
1012
|
-
*/
|
|
1013
|
-
interface WithOptionalFieldTree extends ValidationError {
|
|
1014
|
-
/** The field associated with this error. */
|
|
1015
|
-
readonly fieldTree?: FieldTree<unknown>;
|
|
1016
|
-
}
|
|
1017
|
-
/** @deprecated Use `ValidationError.WithOptionalFieldTree` instead */
|
|
1018
|
-
type WithOptionalField = WithOptionalFieldTree;
|
|
1019
|
-
/**
|
|
1020
|
-
* Validation error with no field.
|
|
1021
|
-
*
|
|
1022
|
-
* This is used to strongly enforce that fields are not allowed in validation result.
|
|
1023
|
-
*/
|
|
1024
|
-
interface WithoutFieldTree extends ValidationError {
|
|
1025
|
-
/** The field associated with this error. */
|
|
1026
|
-
readonly fieldTree?: never;
|
|
1027
|
-
readonly formField?: never;
|
|
1028
|
-
}
|
|
1029
|
-
/** @deprecated Use `ValidationError.WithoutFieldTree` instead */
|
|
1030
|
-
type WithoutField = WithoutFieldTree;
|
|
1031
|
-
}
|
|
1032
|
-
/**
|
|
1033
|
-
* Internal version of `NgValidationError`, we create this separately so we can change its type on
|
|
1034
|
-
* the exported version to a type union of the possible sub-classes.
|
|
1035
|
-
*
|
|
1036
|
-
* @experimental 21.0.0
|
|
1037
|
-
*/
|
|
1038
|
-
declare abstract class _NgValidationError implements ValidationError {
|
|
1039
|
-
/** Brand the class to avoid Typescript structural matching */
|
|
1040
|
-
private __brand;
|
|
1041
|
-
/** Identifies the kind of error. */
|
|
1042
|
-
readonly kind: string;
|
|
1043
|
-
/** The field associated with this error. */
|
|
1044
|
-
readonly fieldTree: FieldTree<unknown>;
|
|
1045
|
-
/** Human readable error message. */
|
|
1046
|
-
readonly message?: string;
|
|
1047
|
-
constructor(options?: ValidationErrorOptions);
|
|
1048
|
-
}
|
|
1049
|
-
/**
|
|
1050
|
-
* An error used to indicate that a required field is empty.
|
|
1051
|
-
*
|
|
1052
|
-
* @category validation
|
|
1053
|
-
* @experimental 21.0.0
|
|
1054
|
-
*/
|
|
1055
|
-
declare class RequiredValidationError extends _NgValidationError {
|
|
1056
|
-
readonly kind = "required";
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* An error used to indicate that a value is lower than the minimum allowed.
|
|
1060
|
-
*
|
|
1061
|
-
* @category validation
|
|
1062
|
-
* @experimental 21.0.0
|
|
1063
|
-
*/
|
|
1064
|
-
declare class MinValidationError extends _NgValidationError {
|
|
1065
|
-
readonly min: number;
|
|
1066
|
-
readonly kind = "min";
|
|
1067
|
-
constructor(min: number, options?: ValidationErrorOptions);
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* An error used to indicate that a value is higher than the maximum allowed.
|
|
1071
|
-
*
|
|
1072
|
-
* @category validation
|
|
1073
|
-
* @experimental 21.0.0
|
|
1074
|
-
*/
|
|
1075
|
-
declare class MaxValidationError extends _NgValidationError {
|
|
1076
|
-
readonly max: number;
|
|
1077
|
-
readonly kind = "max";
|
|
1078
|
-
constructor(max: number, options?: ValidationErrorOptions);
|
|
1079
|
-
}
|
|
1080
|
-
/**
|
|
1081
|
-
* An error used to indicate that a value is shorter than the minimum allowed length.
|
|
1082
|
-
*
|
|
1083
|
-
* @category validation
|
|
1084
|
-
* @experimental 21.0.0
|
|
1085
|
-
*/
|
|
1086
|
-
declare class MinLengthValidationError extends _NgValidationError {
|
|
1087
|
-
readonly minLength: number;
|
|
1088
|
-
readonly kind = "minLength";
|
|
1089
|
-
constructor(minLength: number, options?: ValidationErrorOptions);
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* An error used to indicate that a value is longer than the maximum allowed length.
|
|
1093
|
-
*
|
|
1094
|
-
* @category validation
|
|
1095
|
-
* @experimental 21.0.0
|
|
1096
|
-
*/
|
|
1097
|
-
declare class MaxLengthValidationError extends _NgValidationError {
|
|
1098
|
-
readonly maxLength: number;
|
|
1099
|
-
readonly kind = "maxLength";
|
|
1100
|
-
constructor(maxLength: number, options?: ValidationErrorOptions);
|
|
1101
|
-
}
|
|
1102
|
-
/**
|
|
1103
|
-
* An error used to indicate that a value does not match the required pattern.
|
|
1104
|
-
*
|
|
1105
|
-
* @category validation
|
|
1106
|
-
* @experimental 21.0.0
|
|
1107
|
-
*/
|
|
1108
|
-
declare class PatternValidationError extends _NgValidationError {
|
|
1109
|
-
readonly pattern: RegExp;
|
|
1110
|
-
readonly kind = "pattern";
|
|
1111
|
-
constructor(pattern: RegExp, options?: ValidationErrorOptions);
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* An error used to indicate that a value is not a valid email.
|
|
1115
|
-
*
|
|
1116
|
-
* @category validation
|
|
1117
|
-
* @experimental 21.0.0
|
|
1118
|
-
*/
|
|
1119
|
-
declare class EmailValidationError extends _NgValidationError {
|
|
1120
|
-
readonly kind = "email";
|
|
1121
|
-
}
|
|
1122
|
-
/**
|
|
1123
|
-
* An error used to indicate an issue validating against a standard schema.
|
|
1124
|
-
*
|
|
1125
|
-
* @category validation
|
|
1126
|
-
* @experimental 21.0.0
|
|
1127
|
-
*/
|
|
1128
|
-
declare class StandardSchemaValidationError extends _NgValidationError {
|
|
1129
|
-
readonly issue: StandardSchemaV1.Issue;
|
|
1130
|
-
readonly kind = "standardSchema";
|
|
1131
|
-
constructor(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions);
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* The base class for all built-in, non-custom errors. This class can be used to check if an error
|
|
1135
|
-
* is one of the standard kinds, allowing you to switch on the kind to further narrow the type.
|
|
1136
|
-
*
|
|
1137
|
-
* @example
|
|
1138
|
-
* ```ts
|
|
1139
|
-
* const f = form(...);
|
|
1140
|
-
* for (const e of form().errors()) {
|
|
1141
|
-
* if (e instanceof NgValidationError) {
|
|
1142
|
-
* switch(e.kind) {
|
|
1143
|
-
* case 'required':
|
|
1144
|
-
* console.log('This is required!');
|
|
1145
|
-
* break;
|
|
1146
|
-
* case 'min':
|
|
1147
|
-
* console.log(`Must be at least ${e.min}`);
|
|
1148
|
-
* break;
|
|
1149
|
-
* ...
|
|
1150
|
-
* }
|
|
1151
|
-
* }
|
|
1152
|
-
* }
|
|
1153
|
-
* ```
|
|
1154
|
-
*
|
|
1155
|
-
* @category validation
|
|
1156
|
-
* @experimental 21.0.0
|
|
1157
|
-
*/
|
|
1158
|
-
declare const NgValidationError: abstract new () => NgValidationError;
|
|
1159
|
-
type NgValidationError = RequiredValidationError | MinValidationError | MaxValidationError | MinLengthValidationError | MaxLengthValidationError | PatternValidationError | EmailValidationError | StandardSchemaValidationError;
|
|
1160
|
-
|
|
1161
|
-
/**
|
|
1162
|
-
* Configuration options for signal forms.
|
|
1163
|
-
*
|
|
1164
|
-
* @experimental 21.0.1
|
|
1165
|
-
*/
|
|
1166
|
-
interface SignalFormsConfig {
|
|
1167
|
-
/** A map of CSS class names to predicate functions that determine when to apply them. */
|
|
1168
|
-
classes?: {
|
|
1169
|
-
[className: string]: (state: FormField<unknown>) => boolean;
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Provides configuration options for signal forms.
|
|
1174
|
-
*
|
|
1175
|
-
* @experimental 21.0.1
|
|
1176
|
-
*/
|
|
1177
|
-
declare function provideSignalFormsConfig(config: SignalFormsConfig): Provider[];
|
|
1178
|
-
|
|
1179
|
-
/** Represents a result that should be ignored because its predicate indicates it is not active. */
|
|
1180
|
-
declare const IGNORED: unique symbol;
|
|
1181
|
-
/**
|
|
1182
|
-
* A predicate that indicates whether an `AbstractLogic` instance is currently active, or should be
|
|
1183
|
-
* ignored.
|
|
1184
|
-
*/
|
|
1185
|
-
interface Predicate {
|
|
1186
|
-
/** A boolean logic function that returns true if the logic is considered active. */
|
|
1187
|
-
readonly fn: LogicFn<any, boolean>;
|
|
1188
|
-
/**
|
|
1189
|
-
* The path which this predicate was created for. This is used to determine the correct
|
|
1190
|
-
* `FieldContext` to pass to the predicate function.
|
|
1191
|
-
*/
|
|
1192
|
-
readonly path: SchemaPath<any>;
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Represents a predicate that is bound to a particular depth in the field tree. This is needed for
|
|
1196
|
-
* recursively applied logic to ensure that the predicate is evaluated against the correct
|
|
1197
|
-
* application of that logic.
|
|
1198
|
-
*
|
|
1199
|
-
* Consider the following example:
|
|
1200
|
-
*
|
|
1201
|
-
* ```ts
|
|
1202
|
-
* const s = schema(p => {
|
|
1203
|
-
* disabled(p.data);
|
|
1204
|
-
* applyWhen(p.next, ({valueOf}) => valueOf(p.data) === 1, s);
|
|
1205
|
-
* });
|
|
1206
|
-
*
|
|
1207
|
-
* const f = form(signal({data: 0, next: {data: 1, next: {data: 2, next: undefined}}}), s);
|
|
1208
|
-
*
|
|
1209
|
-
* const isDisabled = f.next.next.data().disabled();
|
|
1210
|
-
* ```
|
|
1211
|
-
*
|
|
1212
|
-
* In order to determine `isDisabled` we need to evaluate the predicate from `applyWhen` *twice*.
|
|
1213
|
-
* Once to see if the schema should be applied to `f.next` and again to see if it should be applied
|
|
1214
|
-
* to `f.next.next`. The `depth` tells us which field we should be evaluating against each time.
|
|
1215
|
-
*/
|
|
1216
|
-
interface BoundPredicate extends Predicate {
|
|
1217
|
-
/** The depth in the field tree at which this predicate is bound. */
|
|
1218
|
-
readonly depth: number;
|
|
1219
|
-
}
|
|
1220
|
-
/**
|
|
1221
|
-
* Base class for all logic. It is responsible for combining the results from multiple individual
|
|
1222
|
-
* logic functions registered in the schema, and using them to derive the value for some associated
|
|
1223
|
-
* piece of field state.
|
|
1224
|
-
*/
|
|
1225
|
-
declare abstract class AbstractLogic<TReturn, TValue = TReturn> {
|
|
1226
|
-
/**
|
|
1227
|
-
* A list of predicates that conditionally enable all logic in this logic instance.
|
|
1228
|
-
* The logic is only enabled when *all* of the predicates evaluate to true.
|
|
1229
|
-
*/
|
|
1230
|
-
private predicates;
|
|
1231
|
-
/** The set of logic functions that contribute to the value of the associated state. */
|
|
1232
|
-
protected readonly fns: Array<LogicFn<any, TValue | typeof IGNORED>>;
|
|
1233
|
-
constructor(
|
|
1234
|
-
/**
|
|
1235
|
-
* A list of predicates that conditionally enable all logic in this logic instance.
|
|
1236
|
-
* The logic is only enabled when *all* of the predicates evaluate to true.
|
|
1237
|
-
*/
|
|
1238
|
-
predicates: ReadonlyArray<BoundPredicate>);
|
|
1239
|
-
/**
|
|
1240
|
-
* Computes the value of the associated field state based on the logic functions and predicates
|
|
1241
|
-
* registered with this logic instance.
|
|
1242
|
-
*/
|
|
1243
|
-
abstract compute(arg: FieldContext<any>): TReturn;
|
|
1244
|
-
/**
|
|
1245
|
-
* The default value that the associated field state should assume if there are no logic functions
|
|
1246
|
-
* registered by the schema (or if the logic is disabled by a predicate).
|
|
1247
|
-
*/
|
|
1248
|
-
abstract get defaultValue(): TReturn;
|
|
1249
|
-
/** Registers a logic function with this logic instance. */
|
|
1250
|
-
push(logicFn: LogicFn<any, TValue>): void;
|
|
1251
|
-
/**
|
|
1252
|
-
* Merges in the logic from another logic instance, subject to the predicates of both the other
|
|
1253
|
-
* instance and this instance.
|
|
1254
|
-
*/
|
|
1255
|
-
mergeIn(other: AbstractLogic<TReturn, TValue>): void;
|
|
1256
|
-
}
|
|
1257
|
-
/** Logic that combines its individual logic function results with logical OR. */
|
|
1258
|
-
declare class BooleanOrLogic extends AbstractLogic<boolean> {
|
|
1259
|
-
get defaultValue(): boolean;
|
|
1260
|
-
compute(arg: FieldContext<any>): boolean;
|
|
1261
|
-
}
|
|
1262
|
-
/**
|
|
1263
|
-
* Logic that combines its individual logic function results by aggregating them in an array.
|
|
1264
|
-
* Depending on its `ignore` function it may ignore certain values, omitting them from the array.
|
|
1265
|
-
*/
|
|
1266
|
-
declare class ArrayMergeIgnoreLogic<TElement, TIgnore = never> extends AbstractLogic<readonly TElement[], TElement | readonly (TElement | TIgnore)[] | TIgnore | undefined | void> {
|
|
1267
|
-
private ignore;
|
|
1268
|
-
/** Creates an instance of this class that ignores `null` values. */
|
|
1269
|
-
static ignoreNull<TElement>(predicates: ReadonlyArray<BoundPredicate>): ArrayMergeIgnoreLogic<TElement, null>;
|
|
1270
|
-
constructor(predicates: ReadonlyArray<BoundPredicate>, ignore: undefined | ((e: TElement | undefined | TIgnore) => e is TIgnore));
|
|
1271
|
-
get defaultValue(): never[];
|
|
1272
|
-
compute(arg: FieldContext<any>): readonly TElement[];
|
|
1273
|
-
}
|
|
1274
|
-
/** Logic that combines its individual logic function results by aggregating them in an array. */
|
|
1275
|
-
declare class ArrayMergeLogic<TElement> extends ArrayMergeIgnoreLogic<TElement, never> {
|
|
1276
|
-
constructor(predicates: ReadonlyArray<BoundPredicate>);
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Container for all the different types of logic that can be applied to a field
|
|
1280
|
-
* (disabled, hidden, errors, etc.)
|
|
1281
|
-
*/
|
|
1282
|
-
declare class LogicContainer {
|
|
1283
|
-
private predicates;
|
|
1284
|
-
/** Logic that determines if the field is hidden. */
|
|
1285
|
-
readonly hidden: BooleanOrLogic;
|
|
1286
|
-
/** Logic that determines reasons for the field being disabled. */
|
|
1287
|
-
readonly disabledReasons: ArrayMergeLogic<DisabledReason>;
|
|
1288
|
-
/** Logic that determines if the field is read-only. */
|
|
1289
|
-
readonly readonly: BooleanOrLogic;
|
|
1290
|
-
/** Logic that produces synchronous validation errors for the field. */
|
|
1291
|
-
readonly syncErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree, null>;
|
|
1292
|
-
/** Logic that produces synchronous validation errors for the field's subtree. */
|
|
1293
|
-
readonly syncTreeErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree, null>;
|
|
1294
|
-
/** Logic that produces asynchronous validation results (errors or 'pending'). */
|
|
1295
|
-
readonly asyncErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree | 'pending', null>;
|
|
1296
|
-
/** A map of metadata keys to the `AbstractLogic` instances that compute their values. */
|
|
1297
|
-
private readonly metadata;
|
|
1298
|
-
/**
|
|
1299
|
-
* Constructs a new `Logic` container.
|
|
1300
|
-
* @param predicates An array of predicates that must all be true for the logic
|
|
1301
|
-
* functions within this container to be active.
|
|
1302
|
-
*/
|
|
1303
|
-
constructor(predicates: ReadonlyArray<BoundPredicate>);
|
|
1304
|
-
/** Checks whether there is logic for the given metadata key. */
|
|
1305
|
-
hasMetadata(key: MetadataKey<any, any, any>): boolean;
|
|
1306
|
-
/**
|
|
1307
|
-
* Gets an iterable of [metadata key, logic function] pairs.
|
|
1308
|
-
* @returns An iterable of metadata keys.
|
|
1309
|
-
*/
|
|
1310
|
-
getMetadataKeys(): MapIterator<MetadataKey<unknown, unknown, unknown>>;
|
|
1311
|
-
/**
|
|
1312
|
-
* Retrieves or creates the `AbstractLogic` for a given metadata key.
|
|
1313
|
-
* @param key The `MetadataKey` for which to get the logic.
|
|
1314
|
-
* @returns The `AbstractLogic` associated with the key.
|
|
1315
|
-
*/
|
|
1316
|
-
getMetadata<T>(key: MetadataKey<any, T, any>): AbstractLogic<T>;
|
|
1317
|
-
/**
|
|
1318
|
-
* Merges logic from another `Logic` instance into this one.
|
|
1319
|
-
* @param other The `Logic` instance to merge from.
|
|
1320
|
-
*/
|
|
1321
|
-
mergeIn(other: LogicContainer): void;
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
/**
|
|
1325
|
-
* Abstract base class for building a `LogicNode`.
|
|
1326
|
-
* This class defines the interface for adding various logic rules (e.g., hidden, disabled)
|
|
1327
|
-
* and data factories to a node in the logic tree.
|
|
1328
|
-
* LogicNodeBuilders are 1:1 with nodes in the Schema tree.
|
|
1329
|
-
*/
|
|
1330
|
-
declare abstract class AbstractLogicNodeBuilder {
|
|
1331
|
-
/** The depth of this node in the schema tree. */
|
|
1332
|
-
protected readonly depth: number;
|
|
1333
|
-
constructor(
|
|
1334
|
-
/** The depth of this node in the schema tree. */
|
|
1335
|
-
depth: number);
|
|
1336
|
-
/** Adds a rule to determine if a field should be hidden. */
|
|
1337
|
-
abstract addHiddenRule(logic: LogicFn<any, boolean>): void;
|
|
1338
|
-
/** Adds a rule to determine if a field should be disabled, and for what reason. */
|
|
1339
|
-
abstract addDisabledReasonRule(logic: LogicFn<any, DisabledReason | undefined>): void;
|
|
1340
|
-
/** Adds a rule to determine if a field should be read-only. */
|
|
1341
|
-
abstract addReadonlyRule(logic: LogicFn<any, boolean>): void;
|
|
1342
|
-
/** Adds a rule for synchronous validation errors for a field. */
|
|
1343
|
-
abstract addSyncErrorRule(logic: LogicFn<any, ValidationResult>): void;
|
|
1344
|
-
/** Adds a rule for synchronous validation errors that apply to a subtree. */
|
|
1345
|
-
abstract addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult>): void;
|
|
1346
|
-
/** Adds a rule for asynchronous validation errors for a field. */
|
|
1347
|
-
abstract addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult>): void;
|
|
1348
|
-
/** Adds a rule to compute metadata for a field. */
|
|
1349
|
-
abstract addMetadataRule<M>(key: MetadataKey<unknown, M, unknown>, logic: LogicFn<any, M>): void;
|
|
1350
|
-
/**
|
|
1351
|
-
* Gets a builder for a child node associated with the given property key.
|
|
1352
|
-
* @param key The property key of the child.
|
|
1353
|
-
* @returns A `LogicNodeBuilder` for the child.
|
|
1354
|
-
*/
|
|
1355
|
-
abstract getChild(key: PropertyKey): LogicNodeBuilder;
|
|
1356
|
-
/**
|
|
1357
|
-
* Checks whether a particular `AbstractLogicNodeBuilder` has been merged into this one.
|
|
1358
|
-
* @param builder The builder to check for.
|
|
1359
|
-
* @returns True if the builder has been merged, false otherwise.
|
|
1360
|
-
*/
|
|
1361
|
-
abstract hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
1362
|
-
/**
|
|
1363
|
-
* Builds the `LogicNode` from the accumulated rules and child builders.
|
|
1364
|
-
* @returns The constructed `LogicNode`.
|
|
1365
|
-
*/
|
|
1366
|
-
build(): LogicNode;
|
|
1367
|
-
}
|
|
1368
|
-
/**
|
|
1369
|
-
* A builder for `LogicNode`. Used to add logic to the final `LogicNode` tree.
|
|
1370
|
-
* This builder supports merging multiple sources of logic, potentially with predicates,
|
|
1371
|
-
* preserving the order of rule application.
|
|
1372
|
-
*/
|
|
1373
|
-
declare class LogicNodeBuilder extends AbstractLogicNodeBuilder {
|
|
1374
|
-
constructor(depth: number);
|
|
1375
|
-
/**
|
|
1376
|
-
* The current `NonMergeableLogicNodeBuilder` being used to add rules directly to this
|
|
1377
|
-
* `LogicNodeBuilder`. Do not use this directly, call `getCurrent()` which will create a current
|
|
1378
|
-
* builder if there is none.
|
|
1379
|
-
*/
|
|
1380
|
-
private current;
|
|
1381
|
-
/**
|
|
1382
|
-
* Stores all builders that contribute to this node, along with any predicates
|
|
1383
|
-
* that gate their application.
|
|
1384
|
-
*/
|
|
1385
|
-
readonly all: {
|
|
1386
|
-
builder: AbstractLogicNodeBuilder;
|
|
1387
|
-
predicate?: Predicate;
|
|
1388
|
-
}[];
|
|
1389
|
-
addHiddenRule(logic: LogicFn<any, boolean>): void;
|
|
1390
|
-
addDisabledReasonRule(logic: LogicFn<any, DisabledReason | undefined>): void;
|
|
1391
|
-
addReadonlyRule(logic: LogicFn<any, boolean>): void;
|
|
1392
|
-
addSyncErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1393
|
-
addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1394
|
-
addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1395
|
-
addMetadataRule<T>(key: MetadataKey<unknown, T, any>, logic: LogicFn<any, T>): void;
|
|
1396
|
-
getChild(key: PropertyKey): LogicNodeBuilder;
|
|
1397
|
-
hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
1398
|
-
/**
|
|
1399
|
-
* Merges logic from another `LogicNodeBuilder` into this one.
|
|
1400
|
-
* If a `predicate` is provided, all logic from the `other` builder will only apply
|
|
1401
|
-
* when the predicate evaluates to true.
|
|
1402
|
-
* @param other The `LogicNodeBuilder` to merge in.
|
|
1403
|
-
* @param predicate An optional predicate to gate the merged logic.
|
|
1404
|
-
*/
|
|
1405
|
-
mergeIn(other: LogicNodeBuilder, predicate?: Predicate): void;
|
|
1406
|
-
/**
|
|
1407
|
-
* Gets the current `NonMergeableLogicNodeBuilder` for adding rules directly to this
|
|
1408
|
-
* `LogicNodeBuilder`. If no current builder exists, a new one is created.
|
|
1409
|
-
* The current builder is cleared whenever `mergeIn` is called to preserve the order
|
|
1410
|
-
* of rules when merging separate builder trees.
|
|
1411
|
-
* @returns The current `NonMergeableLogicNodeBuilder`.
|
|
1412
|
-
*/
|
|
1413
|
-
private getCurrent;
|
|
1414
|
-
/**
|
|
1415
|
-
* Creates a new root `LogicNodeBuilder`.
|
|
1416
|
-
* @returns A new instance of `LogicNodeBuilder`.
|
|
1417
|
-
*/
|
|
1418
|
-
static newRoot(): LogicNodeBuilder;
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* Represents a node in the logic tree, containing all logic applicable
|
|
1422
|
-
* to a specific field or path in the form structure.
|
|
1423
|
-
* LogicNodes are 1:1 with nodes in the Field tree.
|
|
1424
|
-
*/
|
|
1425
|
-
interface LogicNode {
|
|
1426
|
-
/** The collection of logic rules (hidden, disabled, errors, etc.) for this node. */
|
|
1427
|
-
readonly logic: LogicContainer;
|
|
1428
|
-
/**
|
|
1429
|
-
* Retrieves the `LogicNode` for a child identified by the given property key.
|
|
1430
|
-
* @param key The property key of the child.
|
|
1431
|
-
* @returns The `LogicNode` for the specified child.
|
|
1432
|
-
*/
|
|
1433
|
-
getChild(key: PropertyKey): LogicNode;
|
|
1434
|
-
/**
|
|
1435
|
-
* Checks whether the logic from a particular `AbstractLogicNodeBuilder` has been merged into this
|
|
1436
|
-
* node.
|
|
1437
|
-
* @param builder The builder to check for.
|
|
1438
|
-
* @returns True if the builder has been merged, false otherwise.
|
|
1439
|
-
*/
|
|
1440
|
-
hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
/**
|
|
1444
|
-
* Implements the `Schema` concept.
|
|
1445
|
-
*/
|
|
1446
|
-
declare class SchemaImpl {
|
|
1447
|
-
private schemaFn;
|
|
1448
|
-
constructor(schemaFn: SchemaFn<unknown>);
|
|
1449
|
-
/**
|
|
1450
|
-
* Compiles this schema within the current root compilation context. If the schema was previously
|
|
1451
|
-
* compiled within this context, we reuse the cached FieldPathNode, otherwise we create a new one
|
|
1452
|
-
* and cache it in the compilation context.
|
|
1453
|
-
*/
|
|
1454
|
-
compile(): FieldPathNode;
|
|
1455
|
-
/**
|
|
1456
|
-
* Creates a SchemaImpl from the given SchemaOrSchemaFn.
|
|
1457
|
-
*/
|
|
1458
|
-
static create(schema: SchemaImpl | SchemaOrSchemaFn<any>): SchemaImpl;
|
|
1459
|
-
/**
|
|
1460
|
-
* Compiles the given schema in a fresh compilation context. This clears the cached results of any
|
|
1461
|
-
* previous compilations.
|
|
1462
|
-
*/
|
|
1463
|
-
static rootCompile(schema: SchemaImpl | SchemaOrSchemaFn<any> | undefined): FieldPathNode;
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
/**
|
|
1467
|
-
* A path in the schema on which logic is stored so that it can be added to the corresponding field
|
|
1468
|
-
* when the field is created.
|
|
1469
|
-
*/
|
|
1470
|
-
declare class FieldPathNode {
|
|
1471
|
-
/** The property keys used to navigate from the root path to this path. */
|
|
1472
|
-
readonly keys: PropertyKey[];
|
|
1473
|
-
/** The parent of this path node. */
|
|
1474
|
-
private readonly parent;
|
|
1475
|
-
/** The key of this node in its parent. */
|
|
1476
|
-
private readonly keyInParent;
|
|
1477
|
-
/** The root path node from which this path node is descended. */
|
|
1478
|
-
readonly root: FieldPathNode;
|
|
1479
|
-
/**
|
|
1480
|
-
* A map containing all child path nodes that have been created on this path.
|
|
1481
|
-
* Child path nodes are created automatically on first access if they do not exist already.
|
|
1482
|
-
*/
|
|
1483
|
-
private readonly children;
|
|
1484
|
-
/**
|
|
1485
|
-
* A proxy that wraps the path node, allowing navigation to its child paths via property access.
|
|
1486
|
-
*/
|
|
1487
|
-
readonly fieldPathProxy: SchemaPath<any>;
|
|
1488
|
-
/**
|
|
1489
|
-
* For a root path node this will contain the root logic builder. For non-root nodes,
|
|
1490
|
-
* they determine their logic builder from their parent so this is undefined.
|
|
1491
|
-
*/
|
|
1492
|
-
private readonly logicBuilder;
|
|
1493
|
-
protected constructor(
|
|
1494
|
-
/** The property keys used to navigate from the root path to this path. */
|
|
1495
|
-
keys: PropertyKey[], root: FieldPathNode | undefined,
|
|
1496
|
-
/** The parent of this path node. */
|
|
1497
|
-
parent: FieldPathNode | undefined,
|
|
1498
|
-
/** The key of this node in its parent. */
|
|
1499
|
-
keyInParent: PropertyKey | undefined);
|
|
1500
|
-
/** The logic builder used to accumulate logic on this path node. */
|
|
1501
|
-
get builder(): LogicNodeBuilder;
|
|
1502
|
-
/**
|
|
1503
|
-
* Gets the path node for the given child property key.
|
|
1504
|
-
* Child paths are created automatically on first access if they do not exist already.
|
|
1505
|
-
*/
|
|
1506
|
-
getChild(key: PropertyKey): FieldPathNode;
|
|
1507
|
-
/**
|
|
1508
|
-
* Merges in logic from another schema to this one.
|
|
1509
|
-
* @param other The other schema to merge in the logic from
|
|
1510
|
-
* @param predicate A predicate indicating when the merged in logic should be active.
|
|
1511
|
-
*/
|
|
1512
|
-
mergeIn(other: SchemaImpl, predicate?: Predicate): void;
|
|
1513
|
-
/** Extracts the underlying path node from the given path proxy. */
|
|
1514
|
-
static unwrapFieldPath(formPath: SchemaPath<unknown, SchemaPathRules>): FieldPathNode;
|
|
1515
|
-
/** Creates a new root path node to be passed in to a schema function. */
|
|
1516
|
-
static newRoot(): FieldPathNode;
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
/**
|
|
1520
|
-
* Tracks custom metadata associated with a `FieldNode`.
|
|
1521
|
-
*/
|
|
1522
|
-
declare class FieldMetadataState {
|
|
1523
|
-
private readonly node;
|
|
1524
|
-
/** A map of all `MetadataKey` that have been defined for this field. */
|
|
1525
|
-
private readonly metadata;
|
|
1526
|
-
constructor(node: FieldNode);
|
|
1527
|
-
/** Gets the value of an `MetadataKey` for the field. */
|
|
1528
|
-
get<T>(key: MetadataKey<T, unknown, unknown>): T | undefined;
|
|
1529
|
-
/** Checks whether the current metadata state has the given metadata key. */
|
|
1530
|
-
has(key: MetadataKey<any, any, any>): boolean;
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
/**
|
|
1534
|
-
* The non-validation and non-submit state associated with a `FieldNode`, such as touched and dirty
|
|
1535
|
-
* status, as well as derived logical state.
|
|
1536
|
-
*/
|
|
1537
|
-
declare class FieldNodeState {
|
|
1538
|
-
private readonly node;
|
|
1539
|
-
/**
|
|
1540
|
-
* Indicates whether this field has been touched directly by the user (as opposed to indirectly by
|
|
1541
|
-
* touching a child field).
|
|
1542
|
-
*
|
|
1543
|
-
* A field is considered directly touched when a user stops editing it for the first time (i.e. on blur)
|
|
1544
|
-
*/
|
|
1545
|
-
private readonly selfTouched;
|
|
1546
|
-
/**
|
|
1547
|
-
* Indicates whether this field has been dirtied directly by the user (as opposed to indirectly by
|
|
1548
|
-
* dirtying a child field).
|
|
1549
|
-
*
|
|
1550
|
-
* A field is considered directly dirtied if a user changed the value of the field at least once.
|
|
1551
|
-
*/
|
|
1552
|
-
private readonly selfDirty;
|
|
1553
|
-
/**
|
|
1554
|
-
* Marks this specific field as touched.
|
|
1555
|
-
*/
|
|
1556
|
-
markAsTouched(): void;
|
|
1557
|
-
/**
|
|
1558
|
-
* Marks this specific field as dirty.
|
|
1559
|
-
*/
|
|
1560
|
-
markAsDirty(): void;
|
|
1561
|
-
/**
|
|
1562
|
-
* Marks this specific field as not dirty.
|
|
1563
|
-
*/
|
|
1564
|
-
markAsPristine(): void;
|
|
1565
|
-
/**
|
|
1566
|
-
* Marks this specific field as not touched.
|
|
1567
|
-
*/
|
|
1568
|
-
markAsUntouched(): void;
|
|
1569
|
-
/** The {@link FormField} directives that bind this field to a UI control. */
|
|
1570
|
-
readonly formFieldBindings: i0.WritableSignal<readonly FormField<unknown>[]>;
|
|
1571
|
-
constructor(node: FieldNode);
|
|
1572
|
-
/**
|
|
1573
|
-
* Whether this field is considered dirty.
|
|
1574
|
-
*
|
|
1575
|
-
* A field is considered dirty if one of the following is true:
|
|
1576
|
-
* - It was directly dirtied and is interactive
|
|
1577
|
-
* - One of its children is considered dirty
|
|
1578
|
-
*/
|
|
1579
|
-
readonly dirty: Signal<boolean>;
|
|
1580
|
-
/**
|
|
1581
|
-
* Whether this field is considered touched.
|
|
1582
|
-
*
|
|
1583
|
-
* A field is considered touched if one of the following is true:
|
|
1584
|
-
* - It was directly touched and is interactive
|
|
1585
|
-
* - One of its children is considered touched
|
|
1586
|
-
*/
|
|
1587
|
-
readonly touched: Signal<boolean>;
|
|
1588
|
-
/**
|
|
1589
|
-
* The reasons for this field's disablement. This includes disabled reasons for any parent field
|
|
1590
|
-
* that may have been disabled, indirectly causing this field to be disabled as well.
|
|
1591
|
-
* The `field` property of the `DisabledReason` can be used to determine which field ultimately
|
|
1592
|
-
* caused the disablement.
|
|
1593
|
-
*/
|
|
1594
|
-
readonly disabledReasons: Signal<readonly DisabledReason[]>;
|
|
1595
|
-
/**
|
|
1596
|
-
* Whether this field is considered disabled.
|
|
1597
|
-
*
|
|
1598
|
-
* A field is considered disabled if one of the following is true:
|
|
1599
|
-
* - The schema contains logic that directly disabled it
|
|
1600
|
-
* - Its parent field is considered disabled
|
|
1601
|
-
*/
|
|
1602
|
-
readonly disabled: Signal<boolean>;
|
|
1603
|
-
/**
|
|
1604
|
-
* Whether this field is considered readonly.
|
|
1605
|
-
*
|
|
1606
|
-
* A field is considered readonly if one of the following is true:
|
|
1607
|
-
* - The schema contains logic that directly made it readonly
|
|
1608
|
-
* - Its parent field is considered readonly
|
|
1609
|
-
*/
|
|
1610
|
-
readonly readonly: Signal<boolean>;
|
|
1611
|
-
/**
|
|
1612
|
-
* Whether this field is considered hidden.
|
|
1613
|
-
*
|
|
1614
|
-
* A field is considered hidden if one of the following is true:
|
|
1615
|
-
* - The schema contains logic that directly hides it
|
|
1616
|
-
* - Its parent field is considered hidden
|
|
1617
|
-
*/
|
|
1618
|
-
readonly hidden: Signal<boolean>;
|
|
1619
|
-
readonly name: Signal<string>;
|
|
1620
|
-
/**
|
|
1621
|
-
* An optional {@link Debouncer} factory for this field.
|
|
1622
|
-
*/
|
|
1623
|
-
readonly debouncer: Signal<((signal: AbortSignal) => Promise<void> | void) | undefined>;
|
|
1624
|
-
/** Whether this field is considered non-interactive.
|
|
1625
|
-
*
|
|
1626
|
-
* A field is considered non-interactive if one of the following is true:
|
|
1627
|
-
* - It is hidden
|
|
1628
|
-
* - It is disabled
|
|
1629
|
-
* - It is readonly
|
|
1630
|
-
*/
|
|
1631
|
-
private readonly isNonInteractive;
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
/**
|
|
1635
|
-
* State of a `FieldNode` that's associated with form submission.
|
|
1636
|
-
*/
|
|
1637
|
-
declare class FieldSubmitState {
|
|
1638
|
-
private readonly node;
|
|
1639
|
-
/**
|
|
1640
|
-
* Whether this field was directly submitted (as opposed to indirectly by a parent field being submitted)
|
|
1641
|
-
* and is still in the process of submitting.
|
|
1642
|
-
*/
|
|
1643
|
-
readonly selfSubmitting: WritableSignal<boolean>;
|
|
1644
|
-
/** Submission errors that are associated with this field. */
|
|
1645
|
-
readonly submissionErrors: WritableSignal<readonly ValidationError.WithFieldTree[]>;
|
|
1646
|
-
constructor(node: FieldNode);
|
|
1647
|
-
/**
|
|
1648
|
-
* Whether this form is currently in the process of being submitted.
|
|
1649
|
-
* Either because the field was submitted directly, or because a parent field was submitted.
|
|
1650
|
-
*/
|
|
1651
|
-
readonly submitting: Signal<boolean>;
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
interface ValidationState {
|
|
1655
|
-
/**
|
|
1656
|
-
* The full set of synchronous tree errors visible to this field. This includes ones that are
|
|
1657
|
-
* targeted at a descendant field rather than at this field.
|
|
1658
|
-
*/
|
|
1659
|
-
rawSyncTreeErrors: Signal<ValidationError.WithFieldTree[]>;
|
|
1660
|
-
/**
|
|
1661
|
-
* The full set of synchronous errors for this field, including synchronous tree errors and submission
|
|
1662
|
-
* errors. Submission errors are considered "synchronous" because they are imperatively added. From
|
|
1663
|
-
* the perspective of the field state they are either there or not, they are never in a pending
|
|
1664
|
-
* state.
|
|
1665
|
-
*/
|
|
1666
|
-
syncErrors: Signal<ValidationError.WithFieldTree[]>;
|
|
1667
|
-
/**
|
|
1668
|
-
* Whether the field is considered valid according solely to its synchronous validators.
|
|
1669
|
-
* Errors resulting from a previous submit attempt are also considered for this state.
|
|
1670
|
-
*/
|
|
1671
|
-
syncValid: Signal<boolean>;
|
|
1672
|
-
/**
|
|
1673
|
-
* The full set of asynchronous tree errors visible to this field. This includes ones that are
|
|
1674
|
-
* targeted at a descendant field rather than at this field, as well as sentinel 'pending' values
|
|
1675
|
-
* indicating that the validator is still running and an error could still occur.
|
|
1676
|
-
*/
|
|
1677
|
-
rawAsyncErrors: Signal<(ValidationError.WithFieldTree | 'pending')[]>;
|
|
1678
|
-
/**
|
|
1679
|
-
* The asynchronous tree errors visible to this field that are specifically targeted at this field
|
|
1680
|
-
* rather than a descendant. This also includes all 'pending' sentinel values, since those could
|
|
1681
|
-
* theoretically result in errors for this field.
|
|
1682
|
-
*/
|
|
1683
|
-
asyncErrors: Signal<(ValidationError.WithFieldTree | 'pending')[]>;
|
|
1684
|
-
/**
|
|
1685
|
-
* The combined set of all errors that currently apply to this field.
|
|
1686
|
-
*/
|
|
1687
|
-
errors: Signal<ValidationError.WithFieldTree[]>;
|
|
1688
|
-
parseErrors: Signal<ValidationError.WithFormField[]>;
|
|
1689
|
-
/**
|
|
1690
|
-
* The combined set of all errors that currently apply to this field and its descendants.
|
|
1691
|
-
*/
|
|
1692
|
-
errorSummary: Signal<ValidationError.WithFieldTree[]>;
|
|
1693
|
-
/**
|
|
1694
|
-
* Whether this field has any asynchronous validators still pending.
|
|
1695
|
-
*/
|
|
1696
|
-
pending: Signal<boolean>;
|
|
1697
|
-
/**
|
|
1698
|
-
* The validation status of the field.
|
|
1699
|
-
* - The status is 'valid' if neither the field nor any of its children has any errors or pending
|
|
1700
|
-
* validators.
|
|
1701
|
-
* - The status is 'invalid' if the field or any of its children has an error
|
|
1702
|
-
* (regardless of pending validators)
|
|
1703
|
-
* - The status is 'unknown' if neither the field nor any of its children has any errors,
|
|
1704
|
-
* but the field or any of its children does have a pending validator.
|
|
1705
|
-
*
|
|
1706
|
-
* A field is considered valid if *all* of the following are true:
|
|
1707
|
-
* - It has no errors or pending validators
|
|
1708
|
-
* - All of its children are considered valid
|
|
1709
|
-
* A field is considered invalid if *any* of the following are true:
|
|
1710
|
-
* - It has an error
|
|
1711
|
-
* - Any of its children is considered invalid
|
|
1712
|
-
* A field is considered to have unknown validity status if it is not valid or invalid.
|
|
1713
|
-
*/
|
|
1714
|
-
status: Signal<'valid' | 'invalid' | 'unknown'>;
|
|
1715
|
-
/**
|
|
1716
|
-
* Whether the field is considered valid.
|
|
1717
|
-
*
|
|
1718
|
-
* A field is considered valid if *all* of the following are true:
|
|
1719
|
-
* - It has no errors or pending validators
|
|
1720
|
-
* - All of its children are considered valid
|
|
1721
|
-
*
|
|
1722
|
-
* Note: `!valid()` is *not* the same as `invalid()`. Both `valid()` and `invalid()` can be false
|
|
1723
|
-
* if there are currently no errors, but validators are still pending.
|
|
1724
|
-
*/
|
|
1725
|
-
valid: Signal<boolean>;
|
|
1726
|
-
/**
|
|
1727
|
-
* Whether the field is considered invalid.
|
|
1728
|
-
*
|
|
1729
|
-
* A field is considered invalid if *any* of the following are true:
|
|
1730
|
-
* - It has an error
|
|
1731
|
-
* - Any of its children is considered invalid
|
|
1732
|
-
*
|
|
1733
|
-
* Note: `!invalid()` is *not* the same as `valid()`. Both `valid()` and `invalid()` can be false
|
|
1734
|
-
* if there are currently no errors, but validators are still pending.
|
|
1735
|
-
*/
|
|
1736
|
-
invalid: Signal<boolean>;
|
|
1737
|
-
/**
|
|
1738
|
-
* Indicates whether validation should be skipped for this field because it is hidden, disabled,
|
|
1739
|
-
* or readonly.
|
|
1740
|
-
*/
|
|
1741
|
-
shouldSkipValidation: Signal<boolean>;
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1162
|
+
* @category validation
|
|
1163
|
+
* @experimental 21.0.0
|
|
1164
|
+
*/
|
|
1165
|
+
declare function patternError(pattern: RegExp, options?: ValidationErrorOptions): WithoutFieldTree<PatternValidationError>;
|
|
1744
1166
|
/**
|
|
1745
|
-
*
|
|
1746
|
-
*
|
|
1747
|
-
*
|
|
1748
|
-
*
|
|
1749
|
-
*
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
*
|
|
1754
|
-
*
|
|
1755
|
-
*
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
*/
|
|
1781
|
-
private getBindingForFocus;
|
|
1167
|
+
* Create an email format error associated with the target field
|
|
1168
|
+
* @param options The validation error options
|
|
1169
|
+
*
|
|
1170
|
+
* @category validation
|
|
1171
|
+
* @experimental 21.0.0
|
|
1172
|
+
*/
|
|
1173
|
+
declare function emailError(options: WithFieldTree<ValidationErrorOptions>): EmailValidationError;
|
|
1174
|
+
/**
|
|
1175
|
+
* Create an email format error
|
|
1176
|
+
* @param options The optional validation error options
|
|
1177
|
+
*
|
|
1178
|
+
* @category validation
|
|
1179
|
+
* @experimental 21.0.0
|
|
1180
|
+
*/
|
|
1181
|
+
declare function emailError(options?: ValidationErrorOptions): WithoutFieldTree<EmailValidationError>;
|
|
1182
|
+
/**
|
|
1183
|
+
* Common interface for all validation errors.
|
|
1184
|
+
*
|
|
1185
|
+
* This can be returned from validators.
|
|
1186
|
+
*
|
|
1187
|
+
* It's also used by the creation functions to create an instance
|
|
1188
|
+
* (e.g. `requiredError`, `minError`, etc.).
|
|
1189
|
+
*
|
|
1190
|
+
* @see [Signal Form Validation](guide/forms/signals/validation)
|
|
1191
|
+
* @see [Signal Form Validation Errors](guide/forms/signals/validation#validation-errors)
|
|
1192
|
+
* @category validation
|
|
1193
|
+
* @experimental 21.0.0
|
|
1194
|
+
*/
|
|
1195
|
+
interface ValidationError {
|
|
1196
|
+
/** Identifies the kind of error. */
|
|
1197
|
+
readonly kind: string;
|
|
1198
|
+
/** Human readable error message. */
|
|
1199
|
+
readonly message?: string;
|
|
1200
|
+
}
|
|
1201
|
+
declare namespace ValidationError {
|
|
1782
1202
|
/**
|
|
1783
|
-
*
|
|
1203
|
+
* Validation error with an associated field tree.
|
|
1784
1204
|
*
|
|
1785
|
-
* This is
|
|
1786
|
-
*
|
|
1787
|
-
* automatically when recomputed due to `value` being set directly from others sources.
|
|
1788
|
-
*/
|
|
1789
|
-
private readonly pendingSync;
|
|
1790
|
-
get logicNode(): LogicNode;
|
|
1791
|
-
get value(): WritableSignal<unknown>;
|
|
1792
|
-
private _controlValue;
|
|
1793
|
-
get controlValue(): Signal<unknown>;
|
|
1794
|
-
get keyInParent(): Signal<string | number>;
|
|
1795
|
-
get errors(): Signal<ValidationError.WithFieldTree[]>;
|
|
1796
|
-
get parseErrors(): Signal<ValidationError.WithFormField[]>;
|
|
1797
|
-
get errorSummary(): Signal<ValidationError.WithFieldTree[]>;
|
|
1798
|
-
get pending(): Signal<boolean>;
|
|
1799
|
-
get valid(): Signal<boolean>;
|
|
1800
|
-
get invalid(): Signal<boolean>;
|
|
1801
|
-
get dirty(): Signal<boolean>;
|
|
1802
|
-
get touched(): Signal<boolean>;
|
|
1803
|
-
get disabled(): Signal<boolean>;
|
|
1804
|
-
get disabledReasons(): Signal<readonly DisabledReason[]>;
|
|
1805
|
-
get hidden(): Signal<boolean>;
|
|
1806
|
-
get readonly(): Signal<boolean>;
|
|
1807
|
-
get formFieldBindings(): Signal<readonly FormField<unknown>[]>;
|
|
1808
|
-
get submitting(): Signal<boolean>;
|
|
1809
|
-
get name(): Signal<string>;
|
|
1810
|
-
get max(): Signal<number | undefined> | undefined;
|
|
1811
|
-
get maxLength(): Signal<number | undefined> | undefined;
|
|
1812
|
-
get min(): Signal<number | undefined> | undefined;
|
|
1813
|
-
get minLength(): Signal<number | undefined> | undefined;
|
|
1814
|
-
get pattern(): Signal<readonly RegExp[]>;
|
|
1815
|
-
get required(): Signal<boolean>;
|
|
1816
|
-
metadata<M>(key: MetadataKey<M, any, any>): M | undefined;
|
|
1817
|
-
hasMetadata(key: MetadataKey<any, any, any>): boolean;
|
|
1818
|
-
/**
|
|
1819
|
-
* Marks this specific field as touched.
|
|
1205
|
+
* This is returned from field state, e.g., catField.errors() would be of a list of errors with
|
|
1206
|
+
* `field: catField` bound to state.
|
|
1820
1207
|
*/
|
|
1821
|
-
|
|
1208
|
+
interface WithFieldTree extends ValidationError {
|
|
1209
|
+
/** The field associated with this error. */
|
|
1210
|
+
readonly fieldTree: FieldTree<unknown>;
|
|
1211
|
+
readonly formField?: FormField<unknown>;
|
|
1212
|
+
}
|
|
1213
|
+
/** @deprecated Use `ValidationError.WithFieldTree` instead */
|
|
1214
|
+
type WithField = WithFieldTree;
|
|
1822
1215
|
/**
|
|
1823
|
-
*
|
|
1216
|
+
* Validation error with an associated field tree and specific form field binding.
|
|
1824
1217
|
*/
|
|
1825
|
-
|
|
1218
|
+
interface WithFormField extends WithFieldTree {
|
|
1219
|
+
readonly formField: FormField<unknown>;
|
|
1220
|
+
}
|
|
1826
1221
|
/**
|
|
1827
|
-
*
|
|
1828
|
-
*
|
|
1829
|
-
* Note this does not change the data model, which can be reset directly if desired.
|
|
1222
|
+
* Validation error with optional field.
|
|
1830
1223
|
*
|
|
1831
|
-
*
|
|
1832
|
-
|
|
1833
|
-
reset(value?: unknown): void;
|
|
1834
|
-
private _reset;
|
|
1835
|
-
/**
|
|
1836
|
-
* Sets the control value of the field. This value may be debounced before it is synchronized with
|
|
1837
|
-
* the field's {@link value} signal, depending on the debounce configuration.
|
|
1838
|
-
*/
|
|
1839
|
-
setControlValue(newValue: unknown): void;
|
|
1840
|
-
/**
|
|
1841
|
-
* Synchronizes the {@link controlValue} with the {@link value} signal immediately.
|
|
1842
|
-
*/
|
|
1843
|
-
private sync;
|
|
1844
|
-
/**
|
|
1845
|
-
* If there is a pending sync, abort it and sync immediately.
|
|
1224
|
+
* This is generally used in places where the result might have a field.
|
|
1225
|
+
* e.g., as a result of a `validateTree`, or when handling form submission.
|
|
1846
1226
|
*/
|
|
1847
|
-
|
|
1227
|
+
interface WithOptionalFieldTree extends ValidationError {
|
|
1228
|
+
/** The field associated with this error. */
|
|
1229
|
+
readonly fieldTree?: FieldTree<unknown>;
|
|
1230
|
+
}
|
|
1231
|
+
/** @deprecated Use `ValidationError.WithOptionalFieldTree` instead */
|
|
1232
|
+
type WithOptionalField = WithOptionalFieldTree;
|
|
1848
1233
|
/**
|
|
1849
|
-
*
|
|
1234
|
+
* Validation error with no field.
|
|
1850
1235
|
*
|
|
1851
|
-
*
|
|
1852
|
-
* no debouncer is configured, the synchronization happens immediately. If {@link setControlValue}
|
|
1853
|
-
* is called again while a debounce is pending, the previous debounce operation is aborted in
|
|
1854
|
-
* favor of the new one.
|
|
1855
|
-
*/
|
|
1856
|
-
private debounceSync;
|
|
1857
|
-
/**
|
|
1858
|
-
* Creates a new root field node for a new form.
|
|
1236
|
+
* This is used to strongly enforce that fields are not allowed in validation result.
|
|
1859
1237
|
*/
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1238
|
+
interface WithoutFieldTree extends ValidationError {
|
|
1239
|
+
/** The field associated with this error. */
|
|
1240
|
+
readonly fieldTree?: never;
|
|
1241
|
+
readonly formField?: never;
|
|
1242
|
+
}
|
|
1243
|
+
/** @deprecated Use `ValidationError.WithoutFieldTree` instead */
|
|
1244
|
+
type WithoutField = WithoutFieldTree;
|
|
1863
1245
|
}
|
|
1864
1246
|
/**
|
|
1865
|
-
*
|
|
1866
|
-
*
|
|
1247
|
+
* Internal version of `NgValidationError`, we create this separately so we can change its type on
|
|
1248
|
+
* the exported version to a type union of the possible sub-classes.
|
|
1249
|
+
*
|
|
1250
|
+
* @experimental 21.0.0
|
|
1867
1251
|
*/
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1252
|
+
declare abstract class BaseNgValidationError implements ValidationError {
|
|
1253
|
+
/** Brand the class to avoid Typescript structural matching */
|
|
1254
|
+
private __brand;
|
|
1255
|
+
/** Identifies the kind of error. */
|
|
1256
|
+
readonly kind: string;
|
|
1257
|
+
/** The field associated with this error. */
|
|
1258
|
+
readonly fieldTree: FieldTree<unknown>;
|
|
1259
|
+
/** Human readable error message. */
|
|
1260
|
+
readonly message?: string;
|
|
1261
|
+
constructor(options?: ValidationErrorOptions);
|
|
1873
1262
|
}
|
|
1874
|
-
|
|
1875
1263
|
/**
|
|
1876
|
-
*
|
|
1264
|
+
* An error used to indicate that a required field is empty.
|
|
1877
1265
|
*
|
|
1878
|
-
*
|
|
1879
|
-
*
|
|
1266
|
+
* @category validation
|
|
1267
|
+
* @experimental 21.0.0
|
|
1880
1268
|
*/
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
};
|
|
1884
|
-
type ChildNodeCtor = (key: string, trackingKey: TrackingKey | undefined, isArray: boolean) => FieldNode;
|
|
1885
|
-
/** Structural component of a `FieldNode` which tracks its path, parent, and children. */
|
|
1886
|
-
declare abstract class FieldNodeStructure {
|
|
1887
|
-
/**
|
|
1888
|
-
* Computed map of child fields, based on the current value of this field.
|
|
1889
|
-
*
|
|
1890
|
-
* This structure reacts to `this.value` and produces a new `ChildrenData` when the
|
|
1891
|
-
* value changes structurally (fields added/removed/moved).
|
|
1892
|
-
*/
|
|
1893
|
-
protected abstract readonly childrenMap: Signal<ChildrenData | undefined>;
|
|
1894
|
-
/** The field's value. */
|
|
1895
|
-
abstract readonly value: WritableSignal<unknown>;
|
|
1896
|
-
/**
|
|
1897
|
-
* The key of this field in its parent field.
|
|
1898
|
-
* Attempting to read this for the root field will result in an error being thrown.
|
|
1899
|
-
*/
|
|
1900
|
-
abstract readonly keyInParent: Signal<string>;
|
|
1901
|
-
/** The field manager responsible for managing this field. */
|
|
1902
|
-
abstract readonly fieldManager: FormFieldManager;
|
|
1903
|
-
/** The root field that this field descends from. */
|
|
1904
|
-
abstract readonly root: FieldNode;
|
|
1905
|
-
/** The list of property keys to follow to get from the `root` to this field. */
|
|
1906
|
-
abstract readonly pathKeys: Signal<readonly string[]>;
|
|
1907
|
-
/** The parent field of this field. */
|
|
1908
|
-
abstract readonly parent: FieldNode | undefined;
|
|
1909
|
-
readonly logic: LogicNode;
|
|
1910
|
-
readonly node: FieldNode;
|
|
1911
|
-
readonly createChildNode: ChildNodeCtor;
|
|
1912
|
-
/** Added to array elements for tracking purposes. */
|
|
1913
|
-
readonly identitySymbol: symbol;
|
|
1914
|
-
/** Lazily initialized injector. Do not access directly, access via `injector` getter instead. */
|
|
1915
|
-
private _injector;
|
|
1916
|
-
/** Lazily initialized injector. */
|
|
1917
|
-
get injector(): DestroyableInjector;
|
|
1918
|
-
constructor(logic: LogicNode, node: FieldNode, createChildNode: ChildNodeCtor);
|
|
1919
|
-
/** Gets the child fields of this field. */
|
|
1920
|
-
children(): readonly FieldNode[];
|
|
1921
|
-
/** Retrieve a child `FieldNode` of this node by property key. */
|
|
1922
|
-
getChild(key: PropertyKey): FieldNode | undefined;
|
|
1923
|
-
/**
|
|
1924
|
-
* Perform a reduction over a field's children (if any) and return the result.
|
|
1925
|
-
*
|
|
1926
|
-
* Optionally, the reduction is short circuited based on the provided `shortCircuit` function.
|
|
1927
|
-
*/
|
|
1928
|
-
reduceChildren<T>(initialValue: T, fn: (child: FieldNode, value: T) => T, shortCircuit?: (value: T) => boolean): T;
|
|
1929
|
-
/** Destroys the field when it is no longer needed. */
|
|
1930
|
-
destroy(): void;
|
|
1931
|
-
/**
|
|
1932
|
-
* Creates a keyInParent signal for a field node.
|
|
1933
|
-
*
|
|
1934
|
-
* For root nodes, returns ROOT_KEY_IN_PARENT which throws when accessed.
|
|
1935
|
-
* For child nodes, creates a computed that tracks the field's current key in its parent,
|
|
1936
|
-
* with special handling for tracked array elements.
|
|
1937
|
-
*
|
|
1938
|
-
* @param options The field node options
|
|
1939
|
-
* @param identityInParent The tracking identity (only for tracked array children)
|
|
1940
|
-
* @param initialKeyInParent The initial key in parent (only for child nodes)
|
|
1941
|
-
* @returns A signal representing the field's key in its parent
|
|
1942
|
-
*/
|
|
1943
|
-
protected createKeyInParent(options: FieldNodeOptions, identityInParent: TrackingKey | undefined, initialKeyInParent: string | undefined): Signal<string>;
|
|
1944
|
-
protected createChildrenMap(): Signal<ChildrenData | undefined>;
|
|
1945
|
-
/**
|
|
1946
|
-
* Creates a "reader" computed for the given key.
|
|
1947
|
-
*
|
|
1948
|
-
* A reader is a computed signal that memoizes the access of the `FieldNode` stored at this key
|
|
1949
|
-
* (or returns `undefined` if no such field exists). Accessing fields via the reader ensures that
|
|
1950
|
-
* reactive consumers aren't notified unless the field at a key actually changes.
|
|
1951
|
-
*/
|
|
1952
|
-
private createReader;
|
|
1953
|
-
}
|
|
1954
|
-
/** The structural component of a `FieldNode` that is the root of its field tree. */
|
|
1955
|
-
declare class RootFieldNodeStructure extends FieldNodeStructure {
|
|
1956
|
-
readonly fieldManager: FormFieldManager;
|
|
1957
|
-
readonly value: WritableSignal<unknown>;
|
|
1958
|
-
get parent(): undefined;
|
|
1959
|
-
get root(): FieldNode;
|
|
1960
|
-
get pathKeys(): Signal<readonly string[]>;
|
|
1961
|
-
get keyInParent(): Signal<string>;
|
|
1962
|
-
protected readonly childrenMap: Signal<ChildrenData | undefined>;
|
|
1963
|
-
/**
|
|
1964
|
-
* Creates the structure for the root node of a field tree.
|
|
1965
|
-
*
|
|
1966
|
-
* @param node The full field node that this structure belongs to
|
|
1967
|
-
* @param pathNode The path corresponding to this node in the schema
|
|
1968
|
-
* @param logic The logic to apply to this field
|
|
1969
|
-
* @param fieldManager The field manager for this field
|
|
1970
|
-
* @param value The value signal for this field
|
|
1971
|
-
* @param adapter Adapter that knows how to create new fields and appropriate state.
|
|
1972
|
-
* @param createChildNode A factory function to create child nodes for this field.
|
|
1973
|
-
*/
|
|
1974
|
-
constructor(
|
|
1975
|
-
/** The full field node that corresponds to this structure. */
|
|
1976
|
-
node: FieldNode, logic: LogicNode, fieldManager: FormFieldManager, value: WritableSignal<unknown>, createChildNode: ChildNodeCtor);
|
|
1269
|
+
declare class RequiredValidationError extends BaseNgValidationError {
|
|
1270
|
+
readonly kind = "required";
|
|
1977
1271
|
}
|
|
1978
|
-
/**
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
readonly
|
|
1986
|
-
readonly
|
|
1987
|
-
|
|
1988
|
-
/**
|
|
1989
|
-
* Creates the structure for a child field node in a field tree.
|
|
1990
|
-
*
|
|
1991
|
-
* @param node The full field node that this structure belongs to
|
|
1992
|
-
* @param pathNode The path corresponding to this node in the schema
|
|
1993
|
-
* @param logic The logic to apply to this field
|
|
1994
|
-
* @param parent The parent field node for this node
|
|
1995
|
-
* @param identityInParent The identity used to track this field in its parent
|
|
1996
|
-
* @param initialKeyInParent The key of this field in its parent at the time of creation
|
|
1997
|
-
* @param adapter Adapter that knows how to create new fields and appropriate state.
|
|
1998
|
-
* @param createChildNode A factory function to create child nodes for this field.
|
|
1999
|
-
*/
|
|
2000
|
-
constructor(node: FieldNode, logic: LogicNode, parent: ParentFieldNode, identityInParent: TrackingKey | undefined, initialKeyInParent: string, createChildNode: ChildNodeCtor);
|
|
1272
|
+
/**
|
|
1273
|
+
* An error used to indicate that a value is lower than the minimum allowed.
|
|
1274
|
+
*
|
|
1275
|
+
* @category validation
|
|
1276
|
+
* @experimental 21.0.0
|
|
1277
|
+
*/
|
|
1278
|
+
declare class MinValidationError extends BaseNgValidationError {
|
|
1279
|
+
readonly min: number;
|
|
1280
|
+
readonly kind = "min";
|
|
1281
|
+
constructor(min: number, options?: ValidationErrorOptions);
|
|
2001
1282
|
}
|
|
2002
|
-
/**
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
readonly
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
/** The field manager for this field. */
|
|
2013
|
-
readonly fieldManager: FormFieldManager;
|
|
2014
|
-
/** This allows for more granular field and state management, and is currently used for compat. */
|
|
2015
|
-
readonly fieldAdapter: FieldAdapter;
|
|
1283
|
+
/**
|
|
1284
|
+
* An error used to indicate that a value is higher than the maximum allowed.
|
|
1285
|
+
*
|
|
1286
|
+
* @category validation
|
|
1287
|
+
* @experimental 21.0.0
|
|
1288
|
+
*/
|
|
1289
|
+
declare class MaxValidationError extends BaseNgValidationError {
|
|
1290
|
+
readonly max: number;
|
|
1291
|
+
readonly kind = "max";
|
|
1292
|
+
constructor(max: number, options?: ValidationErrorOptions);
|
|
2016
1293
|
}
|
|
2017
|
-
/**
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
readonly
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
/** The key of this field in its parent at the time of creation. */
|
|
2028
|
-
readonly initialKeyInParent: string;
|
|
2029
|
-
/** The identity used to track this field in its parent. */
|
|
2030
|
-
readonly identityInParent: TrackingKey | undefined;
|
|
2031
|
-
/** This allows for more granular field and state management, and is currently used for compat. */
|
|
2032
|
-
readonly fieldAdapter: FieldAdapter;
|
|
1294
|
+
/**
|
|
1295
|
+
* An error used to indicate that a value is shorter than the minimum allowed length.
|
|
1296
|
+
*
|
|
1297
|
+
* @category validation
|
|
1298
|
+
* @experimental 21.0.0
|
|
1299
|
+
*/
|
|
1300
|
+
declare class MinLengthValidationError extends BaseNgValidationError {
|
|
1301
|
+
readonly minLength: number;
|
|
1302
|
+
readonly kind = "minLength";
|
|
1303
|
+
constructor(minLength: number, options?: ValidationErrorOptions);
|
|
2033
1304
|
}
|
|
2034
|
-
/** Options passed when constructing a field node. */
|
|
2035
|
-
type FieldNodeOptions = RootFieldNodeOptions | ChildFieldNodeOptions;
|
|
2036
1305
|
/**
|
|
2037
|
-
*
|
|
1306
|
+
* An error used to indicate that a value is longer than the maximum allowed length.
|
|
1307
|
+
*
|
|
1308
|
+
* @category validation
|
|
1309
|
+
* @experimental 21.0.0
|
|
2038
1310
|
*/
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
readonly byPropertyKey: ReadonlyMap<string, ChildData>;
|
|
2044
|
-
/**
|
|
2045
|
-
* Tracks the instance of child `FieldNode`s by their tracking key, which is always 1:1 with the
|
|
2046
|
-
* fields, even if they move around in the parent.
|
|
2047
|
-
*/
|
|
2048
|
-
readonly byTrackingKey?: ReadonlyMap<TrackingKey, FieldNode>;
|
|
1311
|
+
declare class MaxLengthValidationError extends BaseNgValidationError {
|
|
1312
|
+
readonly maxLength: number;
|
|
1313
|
+
readonly kind = "maxLength";
|
|
1314
|
+
constructor(maxLength: number, options?: ValidationErrorOptions);
|
|
2049
1315
|
}
|
|
2050
1316
|
/**
|
|
2051
|
-
*
|
|
1317
|
+
* An error used to indicate that a value does not match the required pattern.
|
|
1318
|
+
*
|
|
1319
|
+
* @category validation
|
|
1320
|
+
* @experimental 21.0.0
|
|
2052
1321
|
*/
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
* Because this is a computed, it only updates whenever the `FieldNode` at that key changes.
|
|
2058
|
-
* Because `ChildData` is always associated with a specific key via `ChildrenData.byPropertyKey`,
|
|
2059
|
-
* this computed gives a stable way to watch the field stored for a given property and only
|
|
2060
|
-
* receives notifications when that field changes.
|
|
2061
|
-
*/
|
|
2062
|
-
readonly reader: Signal<FieldNode | undefined>;
|
|
2063
|
-
/**
|
|
2064
|
-
* The child `FieldNode` currently stored at this key.
|
|
2065
|
-
*/
|
|
2066
|
-
node: FieldNode;
|
|
1322
|
+
declare class PatternValidationError extends BaseNgValidationError {
|
|
1323
|
+
readonly pattern: RegExp;
|
|
1324
|
+
readonly kind = "pattern";
|
|
1325
|
+
constructor(pattern: RegExp, options?: ValidationErrorOptions);
|
|
2067
1326
|
}
|
|
2068
|
-
|
|
2069
1327
|
/**
|
|
2070
|
-
*
|
|
1328
|
+
* An error used to indicate that a value is not a valid email.
|
|
2071
1329
|
*
|
|
2072
|
-
*
|
|
2073
|
-
*
|
|
2074
|
-
* destroyed, which is the job of the `FormFieldManager`.
|
|
1330
|
+
* @category validation
|
|
1331
|
+
* @experimental 21.0.0
|
|
2075
1332
|
*/
|
|
2076
|
-
declare class
|
|
2077
|
-
readonly
|
|
2078
|
-
readonly rootName: string;
|
|
2079
|
-
constructor(injector: Injector, rootName: string | undefined);
|
|
2080
|
-
/**
|
|
2081
|
-
* Contains all child field structures that have been created as part of the current form.
|
|
2082
|
-
* New child structures are automatically added when they are created.
|
|
2083
|
-
* Structures are destroyed and removed when they are no longer reachable from the root.
|
|
2084
|
-
*/
|
|
2085
|
-
readonly structures: Set<FieldNodeStructure>;
|
|
2086
|
-
/**
|
|
2087
|
-
* Creates an effect that runs when the form's structure changes and checks for structures that
|
|
2088
|
-
* have become unreachable to clean up.
|
|
2089
|
-
*
|
|
2090
|
-
* For example, consider a form wrapped around the following model: `signal([0, 1, 2])`.
|
|
2091
|
-
* This form would have 4 nodes as part of its structure tree.
|
|
2092
|
-
* One structure for the root array, and one structure for each element of the array.
|
|
2093
|
-
* Now imagine the data is updated: `model.set([0])`. In this case the structure for the first
|
|
2094
|
-
* element can still be reached from the root, but the structures for the second and third
|
|
2095
|
-
* elements are now orphaned and not connected to the root. Thus they will be destroyed.
|
|
2096
|
-
*
|
|
2097
|
-
* @param root The root field structure.
|
|
2098
|
-
*/
|
|
2099
|
-
createFieldManagementEffect(root: FieldNodeStructure): void;
|
|
2100
|
-
/**
|
|
2101
|
-
* Collects all structures reachable from the given structure into the given set.
|
|
2102
|
-
*
|
|
2103
|
-
* @param structure The root structure
|
|
2104
|
-
* @param liveStructures The set of reachable structures to populate
|
|
2105
|
-
*/
|
|
2106
|
-
private markStructuresLive;
|
|
1333
|
+
declare class EmailValidationError extends BaseNgValidationError {
|
|
1334
|
+
readonly kind = "email";
|
|
2107
1335
|
}
|
|
1336
|
+
/**
|
|
1337
|
+
* The base class for all built-in, non-custom errors. This class can be used to check if an error
|
|
1338
|
+
* is one of the standard kinds, allowing you to switch on the kind to further narrow the type.
|
|
1339
|
+
*
|
|
1340
|
+
* @example
|
|
1341
|
+
* ```ts
|
|
1342
|
+
* const f = form(...);
|
|
1343
|
+
* for (const e of form().errors()) {
|
|
1344
|
+
* if (e instanceof NgValidationError) {
|
|
1345
|
+
* switch(e.kind) {
|
|
1346
|
+
* case 'required':
|
|
1347
|
+
* console.log('This is required!');
|
|
1348
|
+
* break;
|
|
1349
|
+
* case 'min':
|
|
1350
|
+
* console.log(`Must be at least ${e.min}`);
|
|
1351
|
+
* break;
|
|
1352
|
+
* ...
|
|
1353
|
+
* }
|
|
1354
|
+
* }
|
|
1355
|
+
* }
|
|
1356
|
+
* ```
|
|
1357
|
+
*
|
|
1358
|
+
* @category validation
|
|
1359
|
+
* @experimental 21.0.0
|
|
1360
|
+
*/
|
|
1361
|
+
declare const NgValidationError: abstract new () => NgValidationError;
|
|
1362
|
+
type NgValidationError = RequiredValidationError | MinValidationError | MaxValidationError | MinLengthValidationError | MaxLengthValidationError | PatternValidationError | EmailValidationError | StandardSchemaValidationError;
|
|
2108
1363
|
|
|
2109
1364
|
/**
|
|
2110
|
-
*
|
|
2111
|
-
*
|
|
1365
|
+
* Configuration options for signal forms.
|
|
1366
|
+
*
|
|
1367
|
+
* @experimental 21.0.1
|
|
2112
1368
|
*/
|
|
2113
|
-
interface
|
|
2114
|
-
/**
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
*/
|
|
2119
|
-
createStructure(node: FieldNode, options: FieldNodeOptions): FieldNodeStructure;
|
|
2120
|
-
/**
|
|
2121
|
-
* Creates node validation state
|
|
2122
|
-
* @param param
|
|
2123
|
-
* @param options
|
|
2124
|
-
*/
|
|
2125
|
-
createValidationState(param: FieldNode, options: FieldNodeOptions): ValidationState;
|
|
2126
|
-
/**
|
|
2127
|
-
* Creates node state.
|
|
2128
|
-
* @param param
|
|
2129
|
-
* @param options
|
|
2130
|
-
*/
|
|
2131
|
-
createNodeState(param: FieldNode, options: FieldNodeOptions): FieldNodeState;
|
|
2132
|
-
/**
|
|
2133
|
-
* Creates a custom child node.
|
|
2134
|
-
* @param options
|
|
2135
|
-
*/
|
|
2136
|
-
newChild(options: ChildFieldNodeOptions): FieldNode;
|
|
2137
|
-
/**
|
|
2138
|
-
* Creates a custom root node.
|
|
2139
|
-
* @param fieldManager
|
|
2140
|
-
* @param model
|
|
2141
|
-
* @param pathNode
|
|
2142
|
-
* @param adapter
|
|
2143
|
-
*/
|
|
2144
|
-
newRoot<TValue>(fieldManager: FormFieldManager, model: WritableSignal<TValue>, pathNode: FieldPathNode, adapter: FieldAdapter): FieldNode;
|
|
1369
|
+
interface SignalFormsConfig {
|
|
1370
|
+
/** A map of CSS class names to predicate functions that determine when to apply them. */
|
|
1371
|
+
classes?: {
|
|
1372
|
+
[className: string]: (state: FormField<unknown>) => boolean;
|
|
1373
|
+
};
|
|
2145
1374
|
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Provides configuration options for signal forms.
|
|
1377
|
+
*
|
|
1378
|
+
* @experimental 21.0.1
|
|
1379
|
+
*/
|
|
1380
|
+
declare function provideSignalFormsConfig(config: SignalFormsConfig): Provider[];
|
|
2146
1381
|
|
|
2147
1382
|
/**
|
|
2148
1383
|
* Options that may be specified when creating a form.
|
|
@@ -2150,18 +1385,16 @@ interface FieldAdapter {
|
|
|
2150
1385
|
* @category structure
|
|
2151
1386
|
* @experimental 21.0.0
|
|
2152
1387
|
*/
|
|
2153
|
-
interface FormOptions {
|
|
1388
|
+
interface FormOptions<TModel> {
|
|
2154
1389
|
/**
|
|
2155
1390
|
* The injector to use for dependency injection. If this is not provided, the injector for the
|
|
2156
1391
|
* current [injection context](guide/di/dependency-injection-context), will be used.
|
|
2157
1392
|
*/
|
|
2158
1393
|
injector?: Injector;
|
|
1394
|
+
/** The name of the root form, used in generating name attributes for the fields. */
|
|
2159
1395
|
name?: string;
|
|
2160
|
-
/**
|
|
2161
|
-
|
|
2162
|
-
* Currently this is used to support interop with reactive forms.
|
|
2163
|
-
*/
|
|
2164
|
-
adapter?: FieldAdapter;
|
|
1396
|
+
/** Options that define how to handle form submission. */
|
|
1397
|
+
submission?: FormSubmitOptions<TModel, unknown>;
|
|
2165
1398
|
}
|
|
2166
1399
|
/**
|
|
2167
1400
|
* Creates a form wrapped around the given model data. A form is represented as simply a `FieldTree`
|
|
@@ -2235,7 +1468,7 @@ declare function form<TModel>(model: WritableSignal<TModel>): FieldTree<TModel>;
|
|
|
2235
1468
|
* @category structure
|
|
2236
1469
|
* @experimental 21.0.0
|
|
2237
1470
|
*/
|
|
2238
|
-
declare function form<TModel>(model: WritableSignal<TModel>, schemaOrOptions: SchemaOrSchemaFn<TModel> | FormOptions): FieldTree<TModel>;
|
|
1471
|
+
declare function form<TModel>(model: WritableSignal<TModel>, schemaOrOptions: SchemaOrSchemaFn<TModel> | FormOptions<TModel>): FieldTree<TModel>;
|
|
2239
1472
|
/**
|
|
2240
1473
|
* Creates a form wrapped around the given model data. A form is represented as simply a `FieldTree`
|
|
2241
1474
|
* of the model data.
|
|
@@ -2279,7 +1512,7 @@ declare function form<TModel>(model: WritableSignal<TModel>, schemaOrOptions: Sc
|
|
|
2279
1512
|
* @category structure
|
|
2280
1513
|
* @experimental 21.0.0
|
|
2281
1514
|
*/
|
|
2282
|
-
declare function form<TModel>(model: WritableSignal<TModel>, schema: SchemaOrSchemaFn<TModel>, options: FormOptions): FieldTree<TModel>;
|
|
1515
|
+
declare function form<TModel>(model: WritableSignal<TModel>, schema: SchemaOrSchemaFn<TModel>, options: FormOptions<TModel>): FieldTree<TModel>;
|
|
2283
1516
|
/**
|
|
2284
1517
|
* Applies a schema to each item of an array.
|
|
2285
1518
|
*
|
|
@@ -2386,21 +1619,24 @@ declare function applyWhenValue<TValue>(path: SchemaPath<TValue>, predicate: (va
|
|
|
2386
1619
|
* }
|
|
2387
1620
|
*
|
|
2388
1621
|
* const registrationForm = form(signal({username: 'god', password: ''}));
|
|
2389
|
-
* submit(registrationForm,
|
|
2390
|
-
*
|
|
1622
|
+
* submit(registrationForm, {
|
|
1623
|
+
* action: async (f) => {
|
|
1624
|
+
* return registerNewUser(registrationForm);
|
|
1625
|
+
* }
|
|
2391
1626
|
* });
|
|
2392
1627
|
* registrationForm.username().errors(); // [{kind: 'server', message: 'Username already taken'}]
|
|
2393
1628
|
* ```
|
|
2394
1629
|
*
|
|
2395
1630
|
* @param form The field to submit.
|
|
2396
|
-
* @param
|
|
2397
|
-
*
|
|
1631
|
+
* @param options Options for the submission.
|
|
1632
|
+
* @returns Whether the submission was successful.
|
|
2398
1633
|
* @template TModel The data type of the field being submitted.
|
|
2399
1634
|
*
|
|
2400
1635
|
* @category submission
|
|
2401
1636
|
* @experimental 21.0.0
|
|
2402
1637
|
*/
|
|
2403
|
-
declare function submit<TModel>(form: FieldTree<TModel>,
|
|
1638
|
+
declare function submit<TModel>(form: FieldTree<TModel>, options?: NoInfer<FormSubmitOptions<unknown, TModel>>): Promise<boolean>;
|
|
1639
|
+
declare function submit<TModel>(form: FieldTree<TModel>, action: NoInfer<FormSubmitOptions<unknown, TModel>['action']>): Promise<boolean>;
|
|
2404
1640
|
/**
|
|
2405
1641
|
* Creates a `Schema` that adds logic rules to a form.
|
|
2406
1642
|
* @param fn A **non-reactive** function that sets up reactive logic rules for the form.
|
|
@@ -2412,5 +1648,5 @@ declare function submit<TModel>(form: FieldTree<TModel>, action: (form: FieldTre
|
|
|
2412
1648
|
*/
|
|
2413
1649
|
declare function schema<TValue>(fn: SchemaFn<TValue>): Schema<TValue>;
|
|
2414
1650
|
|
|
2415
|
-
export { EmailValidationError, FORM_FIELD, FormField, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MetadataReducer, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PathKind, PatternValidationError, REQUIRED, RequiredValidationError, SchemaPathRules, StandardSchemaValidationError, ValidationError, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit };
|
|
2416
|
-
export type { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, Debouncer, DisabledReason, FieldContext, FieldState, FieldTree, FieldValidator, FormFieldBindingOptions, FormOptions, ItemFieldContext, ItemType, LogicFn, MaybeFieldTree, MaybeSchemaPathTree, MetadataSetterType, OneOrMany, ReadonlyArrayLike, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SchemaPath, SchemaPathTree, SignalFormsConfig, Subfields, TreeValidationResult, TreeValidator, ValidationResult, ValidationSuccess, Validator, WithField, WithFieldTree, WithOptionalField, WithOptionalFieldTree, WithoutField, WithoutFieldTree };
|
|
1651
|
+
export { BaseNgValidationError, EmailValidationError, FORM_FIELD, FormField, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MetadataReducer, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PathKind, PatternValidationError, REQUIRED, RequiredValidationError, SchemaPathRules, StandardSchemaValidationError, ValidationError, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit, validateStandardSchema, ɵNgFieldDirective };
|
|
1652
|
+
export type { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, Debouncer, DisabledReason, FieldContext, FieldState, FieldTree, FieldValidator, FormFieldBindingOptions, FormOptions, FormSubmitOptions, IgnoreUnknownProperties, ItemFieldContext, ItemType, LogicFn, MaybeFieldTree, MaybeSchemaPathTree, MetadataSetterType, OneOrMany, ReadonlyArrayLike, RemoveStringIndexUnknownKey, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SchemaPath, SchemaPathTree, SignalFormsConfig, Subfields, TreeValidationResult, TreeValidator, ValidationErrorOptions, ValidationResult, ValidationSuccess, Validator, WithField, WithFieldTree, WithOptionalField, WithOptionalFieldTree, WithoutField, WithoutFieldTree };
|