@angular/forms 21.2.0-next.2 → 21.2.0-rc.0
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} +86 -81
- 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 +9 -11
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +1017 -858
- 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 +302 -262
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +1 -1
- package/types/signals.d.ts +119 -15
- package/fesm2022/_structure-chunk.mjs.map +0 -1
|
@@ -1,249 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.2.0-
|
|
2
|
+
* @license Angular v21.2.0-rc.0
|
|
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 {
|
|
9
|
-
import * as _angular_forms from '@angular/forms';
|
|
8
|
+
import { WritableSignal, Signal, InjectionToken, Injector, Provider } from '@angular/core';
|
|
10
9
|
import { AbstractControl, ValidationErrors, FormControlStatus, ControlValueAccessor, ValidatorFn } from '@angular/forms';
|
|
11
10
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
12
11
|
|
|
13
12
|
/**
|
|
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
|
|
37
|
-
*/
|
|
38
|
-
interface MetadataReducer<TAcc, TItem> {
|
|
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>;
|
|
60
|
-
/**
|
|
61
|
-
* Represents metadata that is aggregated from multiple parts according to the key's reducer
|
|
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.
|
|
69
|
-
*
|
|
70
|
-
* @experimental 21.0.0
|
|
71
|
-
*/
|
|
72
|
-
declare class MetadataKey<TRead, TWrite, TAcc> {
|
|
73
|
-
readonly reducer: MetadataReducer<TAcc, TWrite>;
|
|
74
|
-
readonly create: ((s: Signal<TAcc>) => TRead) | undefined;
|
|
75
|
-
private brand;
|
|
76
|
-
/** Use {@link reducedMetadataKey}. */
|
|
77
|
-
protected constructor(reducer: MetadataReducer<TAcc, TWrite>, create: ((s: Signal<TAcc>) => TRead) | undefined);
|
|
78
|
-
}
|
|
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
|
-
* Utility type that removes a string index key when its value is `unknown`,
|
|
181
|
-
* i.e. `{[key: string]: unknown}`. It allows specific string keys to pass through, even if their
|
|
182
|
-
* value is `unknown`, e.g. `{key: unknown}`.
|
|
183
|
-
*
|
|
184
|
-
* @experimental 21.0.0
|
|
185
|
-
*/
|
|
186
|
-
type RemoveStringIndexUnknownKey<K, V> = string extends K ? unknown extends V ? never : K : K;
|
|
187
|
-
/**
|
|
188
|
-
* Utility type that recursively ignores unknown string index properties on the given object.
|
|
189
|
-
* We use this on the `TSchema` type in `validateStandardSchema` in order to accommodate Zod's
|
|
190
|
-
* `looseObject` which includes `{[key: string]: unknown}` as part of the type.
|
|
191
|
-
*
|
|
192
|
-
* @experimental 21.0.0
|
|
193
|
-
*/
|
|
194
|
-
type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
|
|
195
|
-
[K in keyof T as RemoveStringIndexUnknownKey<K, T[K]>]: IgnoreUnknownProperties<T[K]>;
|
|
196
|
-
} : T;
|
|
197
|
-
/**
|
|
198
|
-
* Validates a field using a `StandardSchemaV1` compatible validator (e.g. a Zod validator).
|
|
199
|
-
*
|
|
200
|
-
* See https://github.com/standard-schema/standard-schema for more about standard schema.
|
|
201
|
-
*
|
|
202
|
-
* @param path The `FieldPath` to the field to validate.
|
|
203
|
-
* @param schema The standard schema compatible validator to use for validation.
|
|
204
|
-
* @template TSchema The type validated by the schema. This may be either the full `TValue` type,
|
|
205
|
-
* or a partial of it.
|
|
206
|
-
* @template TValue The type of value stored in the field being validated.
|
|
207
|
-
*
|
|
208
|
-
* @see [Signal Form Schema Validation](guide/forms/signals/validation#integration-with-schema-validation-libraries)
|
|
209
|
-
* @category validation
|
|
210
|
-
* @experimental 21.0.0
|
|
211
|
-
*/
|
|
212
|
-
declare function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProperties<TSchema>>(path: SchemaPath<TModel> & SchemaPathTree<TModel>, schema: StandardSchemaV1<TSchema>): void;
|
|
213
|
-
/**
|
|
214
|
-
* Create a standard schema issue error associated with the target field
|
|
215
|
-
* @param issue The standard schema issue
|
|
216
|
-
* @param options The validation error options
|
|
217
|
-
*
|
|
218
|
-
* @category validation
|
|
219
|
-
* @experimental 21.0.0
|
|
220
|
-
*/
|
|
221
|
-
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options: WithFieldTree<ValidationErrorOptions>): StandardSchemaValidationError;
|
|
222
|
-
/**
|
|
223
|
-
* Create a standard schema issue error
|
|
224
|
-
* @param issue The standard schema issue
|
|
225
|
-
* @param options The optional validation error options
|
|
226
|
-
*
|
|
227
|
-
* @category validation
|
|
228
|
-
* @experimental 21.0.0
|
|
13
|
+
* Symbol used to retain generic type information when it would otherwise be lost.
|
|
229
14
|
*/
|
|
230
|
-
declare
|
|
15
|
+
declare const ɵɵTYPE: unique symbol;
|
|
231
16
|
/**
|
|
232
|
-
*
|
|
17
|
+
* Options that can be specified when submitting a form.
|
|
233
18
|
*
|
|
234
|
-
* @
|
|
235
|
-
* @experimental 21.0.0
|
|
19
|
+
* @experimental 21.2.0
|
|
236
20
|
*/
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
21
|
+
interface FormSubmitOptions<TRootModel, TSubmittedModel> {
|
|
22
|
+
/**
|
|
23
|
+
* Function to run when submitting the form data (when form is valid).
|
|
24
|
+
*
|
|
25
|
+
* @param field The contextually relevant field for this action function (the root field when
|
|
26
|
+
* specified during form creation, and the submitted field when specified as part of the
|
|
27
|
+
* `submit()` call)
|
|
28
|
+
* @param detail An object containing the root field of the submitted form as well as the
|
|
29
|
+
* submitted field itself
|
|
30
|
+
*/
|
|
31
|
+
action: (field: FieldTree<TRootModel & TSubmittedModel>, detail: {
|
|
32
|
+
root: FieldTree<TRootModel>;
|
|
33
|
+
submitted: FieldTree<TSubmittedModel>;
|
|
34
|
+
}) => Promise<TreeValidationResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Function to run when attempting to submit the form data but validation is failing.
|
|
37
|
+
*
|
|
38
|
+
* @param field The contextually relevant field for this onInvalid function (the root field when
|
|
39
|
+
* specified during form creation, and the submitted field when specified as part of the
|
|
40
|
+
* `submit()` call)
|
|
41
|
+
* @param detail An object containing the root field of the submitted form as well as the
|
|
42
|
+
* submitted field itself
|
|
43
|
+
*/
|
|
44
|
+
onInvalid?: (field: FieldTree<TRootModel & TSubmittedModel>, detail: {
|
|
45
|
+
root: FieldTree<TRootModel>;
|
|
46
|
+
submitted: FieldTree<TSubmittedModel>;
|
|
47
|
+
}) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Whether to ignore any of the validators when submitting:
|
|
50
|
+
* - 'pending': Will submit if there are no invalid validators, pending validators do not block submission (default)
|
|
51
|
+
* - 'none': Will not submit unless all validators are passing, pending validators block submission
|
|
52
|
+
* - 'ignore': Will always submit regardless of invalid or pending validators
|
|
53
|
+
*/
|
|
54
|
+
ignoreValidators?: 'pending' | 'none' | 'all';
|
|
241
55
|
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Symbol used to retain generic type information when it would otherwise be lost.
|
|
245
|
-
*/
|
|
246
|
-
declare const ɵɵTYPE: unique symbol;
|
|
247
56
|
/**
|
|
248
57
|
* A type that represents either a single value of type `T` or a readonly array of `T`.
|
|
249
58
|
* @template T The type of the value(s).
|
|
@@ -343,6 +152,16 @@ type ValidationResult<E extends ValidationError = ValidationError> = ValidationS
|
|
|
343
152
|
* @experimental 21.0.0
|
|
344
153
|
*/
|
|
345
154
|
type AsyncValidationResult<E extends ValidationError = ValidationError> = ValidationResult<E> | 'pending';
|
|
155
|
+
/**
|
|
156
|
+
* A field accessor function that returns the state of the field.
|
|
157
|
+
*
|
|
158
|
+
* @template TValue The type of the value stored in the field.
|
|
159
|
+
* @template TKey The type of the property key which this field resides under in its parent.
|
|
160
|
+
*
|
|
161
|
+
* @category types
|
|
162
|
+
* @experimental 21.2.0
|
|
163
|
+
*/
|
|
164
|
+
type Field<TValue, TKey extends string | number = string | number> = () => FieldState<TValue, TKey>;
|
|
346
165
|
/**
|
|
347
166
|
* An object that represents a tree of fields in a form. This includes both primitive value fields
|
|
348
167
|
* (e.g. fields that contain a `string` or `number`), as well as "grouping fields" that contain
|
|
@@ -398,6 +217,10 @@ type MaybeFieldTree<TModel, TKey extends string | number = string | number> = (T
|
|
|
398
217
|
* @experimental 21.0.0
|
|
399
218
|
*/
|
|
400
219
|
interface FieldState<TValue, TKey extends string | number = string | number> {
|
|
220
|
+
/**
|
|
221
|
+
* The {@link FieldTree} associated with this field state.
|
|
222
|
+
*/
|
|
223
|
+
readonly fieldTree: FieldTree<unknown, TKey>;
|
|
401
224
|
/**
|
|
402
225
|
* A writable signal containing the value for this field.
|
|
403
226
|
*
|
|
@@ -823,6 +646,236 @@ type ItemType<T extends Object> = T extends ReadonlyArray<any> ? T[number] : T[k
|
|
|
823
646
|
*/
|
|
824
647
|
type Debouncer<TValue, TPathKind extends PathKind = PathKind.Root> = (context: FieldContext<TValue, TPathKind>, abortSignal: AbortSignal) => Promise<void> | void;
|
|
825
648
|
|
|
649
|
+
/**
|
|
650
|
+
* Sets a value for the {@link MetadataKey} for this field.
|
|
651
|
+
*
|
|
652
|
+
* This value is combined via a reduce operation defined by the particular key,
|
|
653
|
+
* since multiple rules in the schema might set values for it.
|
|
654
|
+
*
|
|
655
|
+
* @param path The target path to set the metadata for.
|
|
656
|
+
* @param key The metadata key
|
|
657
|
+
* @param logic A function that receives the `FieldContext` and returns a value for the metadata.
|
|
658
|
+
* @template TValue The type of value stored in the field the logic is bound to.
|
|
659
|
+
* @template TKey The type of metadata key.
|
|
660
|
+
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
661
|
+
*
|
|
662
|
+
* @category logic
|
|
663
|
+
* @experimental 21.0.0
|
|
664
|
+
*/
|
|
665
|
+
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;
|
|
666
|
+
/**
|
|
667
|
+
* A reducer that determines the accumulated value for a metadata key by reducing the individual
|
|
668
|
+
* values contributed from `metadata()` rules.
|
|
669
|
+
*
|
|
670
|
+
* @template TAcc The accumulated type of the reduce operation.
|
|
671
|
+
* @template TItem The type of the individual items that are reduced over.
|
|
672
|
+
* @experimental 21.0.2
|
|
673
|
+
*/
|
|
674
|
+
interface MetadataReducer<TAcc, TItem> {
|
|
675
|
+
/** The reduce function. */
|
|
676
|
+
reduce: (acc: TAcc, item: TItem) => TAcc;
|
|
677
|
+
/** Gets the initial accumulated value. */
|
|
678
|
+
getInitial: () => TAcc;
|
|
679
|
+
}
|
|
680
|
+
declare const MetadataReducer: {
|
|
681
|
+
/** Creates a reducer that accumulates a list of its individual item values. */
|
|
682
|
+
readonly list: <TItem>() => MetadataReducer<TItem[], TItem | undefined>;
|
|
683
|
+
/** Creates a reducer that accumulates the min of its individual item values. */
|
|
684
|
+
readonly min: () => MetadataReducer<number | undefined, number | undefined>;
|
|
685
|
+
/** Creates a reducer that accumulates a the max of its individual item values. */
|
|
686
|
+
readonly max: () => MetadataReducer<number | undefined, number | undefined>;
|
|
687
|
+
/** Creates a reducer that logically or's its accumulated value with each individual item value. */
|
|
688
|
+
readonly or: () => MetadataReducer<boolean, boolean>;
|
|
689
|
+
/** Creates a reducer that logically and's its accumulated value with each individual item value. */
|
|
690
|
+
readonly and: () => MetadataReducer<boolean, boolean>;
|
|
691
|
+
/** Creates a reducer that always takes the next individual item value as the accumulated value. */
|
|
692
|
+
readonly override: typeof override;
|
|
693
|
+
};
|
|
694
|
+
declare function override<T>(): MetadataReducer<T | undefined, T>;
|
|
695
|
+
declare function override<T>(getInitial: () => T): MetadataReducer<T, T>;
|
|
696
|
+
/**
|
|
697
|
+
* Represents metadata that is aggregated from multiple parts according to the key's reducer
|
|
698
|
+
* function. A value can be contributed to the aggregated value for a field using an
|
|
699
|
+
* `metadata` rule in the schema. There may be multiple rules in a schema that contribute
|
|
700
|
+
* values to the same `MetadataKey` of the same field.
|
|
701
|
+
*
|
|
702
|
+
* @template TRead The type read from the `FieldState` for this key
|
|
703
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
704
|
+
* @template TAcc The type of the reducer's accumulated value.
|
|
705
|
+
*
|
|
706
|
+
* @experimental 21.0.0
|
|
707
|
+
*/
|
|
708
|
+
declare class MetadataKey<TRead, TWrite, TAcc> {
|
|
709
|
+
readonly reducer: MetadataReducer<TAcc, TWrite>;
|
|
710
|
+
readonly create: ((s: Signal<TAcc>) => TRead) | undefined;
|
|
711
|
+
private brand;
|
|
712
|
+
/** Use {@link reducedMetadataKey}. */
|
|
713
|
+
protected constructor(reducer: MetadataReducer<TAcc, TWrite>, create: ((s: Signal<TAcc>) => TRead) | undefined);
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Extracts the the type that can be set into the given metadata key type using the `metadata()` rule.
|
|
717
|
+
*
|
|
718
|
+
* @template TKey The `MetadataKey` type
|
|
719
|
+
*
|
|
720
|
+
* @experimental 21.0.0
|
|
721
|
+
*/
|
|
722
|
+
type MetadataSetterType<TKey> = TKey extends MetadataKey<any, infer TWrite, any> ? TWrite : never;
|
|
723
|
+
/**
|
|
724
|
+
* Creates a metadata key used to contain a computed value.
|
|
725
|
+
* The last value set on a given field tree node overrides any previously set values.
|
|
726
|
+
*
|
|
727
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
728
|
+
*
|
|
729
|
+
* @experimental 21.0.0
|
|
730
|
+
*/
|
|
731
|
+
declare function createMetadataKey<TWrite>(): MetadataKey<Signal<TWrite | undefined>, TWrite, TWrite | undefined>;
|
|
732
|
+
/**
|
|
733
|
+
* Creates a metadata key used to contain a computed value.
|
|
734
|
+
*
|
|
735
|
+
* @param reducer The reducer used to combine individually set values into the final computed value.
|
|
736
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
737
|
+
* @template TAcc The type of the reducer's accumulated value.
|
|
738
|
+
*
|
|
739
|
+
* @experimental 21.0.0
|
|
740
|
+
*/
|
|
741
|
+
declare function createMetadataKey<TWrite, TAcc>(reducer: MetadataReducer<TAcc, TWrite>): MetadataKey<Signal<TAcc>, TWrite, TAcc>;
|
|
742
|
+
/**
|
|
743
|
+
* Creates a metadata key that exposes a managed value based on the accumulated result of the values
|
|
744
|
+
* written to the key. The accumulated value takes the last value set on a given field tree node,
|
|
745
|
+
* overriding any previously set values.
|
|
746
|
+
*
|
|
747
|
+
* @param create A function that receives a signal of the accumulated value and returns the managed
|
|
748
|
+
* value based on it. This function runs during the construction of the `FieldTree` node,
|
|
749
|
+
* and runs in the injection context of that node.
|
|
750
|
+
* @template TRead The type read from the `FieldState` for this key
|
|
751
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
752
|
+
*
|
|
753
|
+
* @experimental 21.0.0
|
|
754
|
+
*/
|
|
755
|
+
declare function createManagedMetadataKey<TRead, TWrite>(create: (s: Signal<TWrite | undefined>) => TRead): MetadataKey<TRead, TWrite, TWrite | undefined>;
|
|
756
|
+
/**
|
|
757
|
+
* Creates a metadata key that exposes a managed value based on the accumulated result of the values
|
|
758
|
+
* written to the key.
|
|
759
|
+
*
|
|
760
|
+
* @param create A function that receives a signal of the accumulated value and returns the managed
|
|
761
|
+
* value based on it. This function runs during the construction of the `FieldTree` node,
|
|
762
|
+
* and runs in the injection context of that node.
|
|
763
|
+
* @param reducer The reducer used to combine individual value written to the key,
|
|
764
|
+
* this will determine the accumulated value that the create function receives.
|
|
765
|
+
* @template TRead The type read from the `FieldState` for this key
|
|
766
|
+
* @template TWrite The type written to this key using the `metadata()` rule
|
|
767
|
+
* @template TAcc The type of the reducer's accumulated value.
|
|
768
|
+
*
|
|
769
|
+
* @experimental 21.0.0
|
|
770
|
+
*/
|
|
771
|
+
declare function createManagedMetadataKey<TRead, TWrite, TAcc>(create: (s: Signal<TAcc>) => TRead, reducer: MetadataReducer<TAcc, TWrite>): MetadataKey<TRead, TWrite, TAcc>;
|
|
772
|
+
/**
|
|
773
|
+
* A {@link MetadataKey} representing whether the field is required.
|
|
774
|
+
*
|
|
775
|
+
* @category validation
|
|
776
|
+
* @experimental 21.0.0
|
|
777
|
+
*/
|
|
778
|
+
declare const REQUIRED: MetadataKey<Signal<boolean>, boolean, boolean>;
|
|
779
|
+
/**
|
|
780
|
+
* A {@link MetadataKey} representing the min value of the field.
|
|
781
|
+
*
|
|
782
|
+
* @category validation
|
|
783
|
+
* @experimental 21.0.0
|
|
784
|
+
*/
|
|
785
|
+
declare const MIN: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
786
|
+
/**
|
|
787
|
+
* A {@link MetadataKey} representing the max value of the field.
|
|
788
|
+
*
|
|
789
|
+
* @category validation
|
|
790
|
+
* @experimental 21.0.0
|
|
791
|
+
*/
|
|
792
|
+
declare const MAX: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
793
|
+
/**
|
|
794
|
+
* A {@link MetadataKey} representing the min length of the field.
|
|
795
|
+
*
|
|
796
|
+
* @category validation
|
|
797
|
+
* @experimental 21.0.0
|
|
798
|
+
*/
|
|
799
|
+
declare const MIN_LENGTH: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
800
|
+
/**
|
|
801
|
+
* A {@link MetadataKey} representing the max length of the field.
|
|
802
|
+
*
|
|
803
|
+
* @category validation
|
|
804
|
+
* @experimental 21.0.0
|
|
805
|
+
*/
|
|
806
|
+
declare const MAX_LENGTH: MetadataKey<Signal<number | undefined>, number | undefined, number | undefined>;
|
|
807
|
+
/**
|
|
808
|
+
* A {@link MetadataKey} representing the patterns the field must match.
|
|
809
|
+
*
|
|
810
|
+
* @category validation
|
|
811
|
+
* @experimental 21.0.0
|
|
812
|
+
*/
|
|
813
|
+
declare const PATTERN: MetadataKey<Signal<RegExp[]>, RegExp | undefined, RegExp[]>;
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Utility type that removes a string index key when its value is `unknown`,
|
|
817
|
+
* i.e. `{[key: string]: unknown}`. It allows specific string keys to pass through, even if their
|
|
818
|
+
* value is `unknown`, e.g. `{key: unknown}`.
|
|
819
|
+
*
|
|
820
|
+
* @experimental 21.0.0
|
|
821
|
+
*/
|
|
822
|
+
type RemoveStringIndexUnknownKey<K, V> = string extends K ? unknown extends V ? never : K : K;
|
|
823
|
+
/**
|
|
824
|
+
* Utility type that recursively ignores unknown string index properties on the given object.
|
|
825
|
+
* We use this on the `TSchema` type in `validateStandardSchema` in order to accommodate Zod's
|
|
826
|
+
* `looseObject` which includes `{[key: string]: unknown}` as part of the type.
|
|
827
|
+
*
|
|
828
|
+
* @experimental 21.0.0
|
|
829
|
+
*/
|
|
830
|
+
type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
|
|
831
|
+
[K in keyof T as RemoveStringIndexUnknownKey<K, T[K]>]: IgnoreUnknownProperties<T[K]>;
|
|
832
|
+
} : T;
|
|
833
|
+
/**
|
|
834
|
+
* Validates a field using a `StandardSchemaV1` compatible validator (e.g. a Zod validator).
|
|
835
|
+
*
|
|
836
|
+
* See https://github.com/standard-schema/standard-schema for more about standard schema.
|
|
837
|
+
*
|
|
838
|
+
* @param path The `FieldPath` to the field to validate.
|
|
839
|
+
* @param schema The standard schema compatible validator to use for validation, or a LogicFn that returns the schema.
|
|
840
|
+
* @template TSchema The type validated by the schema. This may be either the full `TValue` type,
|
|
841
|
+
* or a partial of it.
|
|
842
|
+
* @template TValue The type of value stored in the field being validated.
|
|
843
|
+
*
|
|
844
|
+
* @see [Signal Form Schema Validation](guide/forms/signals/validation#integration-with-schema-validation-libraries)
|
|
845
|
+
* @category validation
|
|
846
|
+
* @experimental 21.0.0
|
|
847
|
+
*/
|
|
848
|
+
declare function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProperties<TSchema>>(path: SchemaPath<TModel> & SchemaPathTree<TModel>, schema: StandardSchemaV1<TSchema> | LogicFn<TModel, StandardSchemaV1<unknown> | undefined>): void;
|
|
849
|
+
/**
|
|
850
|
+
* Create a standard schema issue error associated with the target field
|
|
851
|
+
* @param issue The standard schema issue
|
|
852
|
+
* @param options The validation error options
|
|
853
|
+
*
|
|
854
|
+
* @category validation
|
|
855
|
+
* @experimental 21.0.0
|
|
856
|
+
*/
|
|
857
|
+
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options: WithFieldTree<ValidationErrorOptions>): StandardSchemaValidationError;
|
|
858
|
+
/**
|
|
859
|
+
* Create a standard schema issue error
|
|
860
|
+
* @param issue The standard schema issue
|
|
861
|
+
* @param options The optional validation error options
|
|
862
|
+
*
|
|
863
|
+
* @category validation
|
|
864
|
+
* @experimental 21.0.0
|
|
865
|
+
*/
|
|
866
|
+
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions): WithoutFieldTree<StandardSchemaValidationError>;
|
|
867
|
+
/**
|
|
868
|
+
* An error used to indicate an issue validating against a standard schema.
|
|
869
|
+
*
|
|
870
|
+
* @category validation
|
|
871
|
+
* @experimental 21.0.0
|
|
872
|
+
*/
|
|
873
|
+
declare class StandardSchemaValidationError extends BaseNgValidationError {
|
|
874
|
+
readonly issue: StandardSchemaV1.Issue;
|
|
875
|
+
readonly kind = "standardSchema";
|
|
876
|
+
constructor(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions);
|
|
877
|
+
}
|
|
878
|
+
|
|
826
879
|
/**
|
|
827
880
|
* Represents a combination of `NgControl` and `AbstractControl`.
|
|
828
881
|
*
|
|
@@ -884,10 +937,6 @@ interface FormFieldBindingOptions {
|
|
|
884
937
|
* asked to focus this binding.
|
|
885
938
|
*/
|
|
886
939
|
readonly focus?: (focusOptions?: FocusOptions) => void;
|
|
887
|
-
/**
|
|
888
|
-
* Source of parse errors for this binding.
|
|
889
|
-
*/
|
|
890
|
-
readonly parseErrors?: Signal<ValidationError.WithoutFieldTree[]>;
|
|
891
940
|
}
|
|
892
941
|
/**
|
|
893
942
|
* Lightweight DI token provided by the {@link FormField} directive.
|
|
@@ -916,11 +965,11 @@ declare const FORM_FIELD: InjectionToken<FormField<unknown>>;
|
|
|
916
965
|
* @experimental 21.0.0
|
|
917
966
|
*/
|
|
918
967
|
declare class FormField<T> {
|
|
919
|
-
readonly
|
|
968
|
+
readonly field: i0.InputSignal<Field<T>>;
|
|
920
969
|
/**
|
|
921
970
|
* `FieldState` for the currently bound field.
|
|
922
971
|
*/
|
|
923
|
-
readonly state: Signal<
|
|
972
|
+
readonly state: Signal<FieldState<T, string | number>>;
|
|
924
973
|
/**
|
|
925
974
|
* The node injector for the element this field binding.
|
|
926
975
|
*/
|
|
@@ -975,7 +1024,7 @@ declare class FormField<T> {
|
|
|
975
1024
|
*/
|
|
976
1025
|
readonly [ɵNgFieldDirective]: true;
|
|
977
1026
|
static ɵfac: i0.ɵɵFactoryDeclaration<FormField<any>, never>;
|
|
978
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<FormField<any>, "[formField]", ["formField"], { "
|
|
1027
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<FormField<any>, "[formField]", ["formField"], { "field": { "alias": "formField"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
979
1028
|
}
|
|
980
1029
|
|
|
981
1030
|
/**
|
|
@@ -1293,6 +1342,15 @@ declare class PatternValidationError extends BaseNgValidationError {
|
|
|
1293
1342
|
declare class EmailValidationError extends BaseNgValidationError {
|
|
1294
1343
|
readonly kind = "email";
|
|
1295
1344
|
}
|
|
1345
|
+
/**
|
|
1346
|
+
* An error used to indicate that a value entered in a native input does not parse.
|
|
1347
|
+
*
|
|
1348
|
+
* @category validation
|
|
1349
|
+
* @experimental 21.2.0
|
|
1350
|
+
*/
|
|
1351
|
+
declare class NativeInputParseError extends BaseNgValidationError {
|
|
1352
|
+
readonly kind = "parse";
|
|
1353
|
+
}
|
|
1296
1354
|
/**
|
|
1297
1355
|
* The base class for all built-in, non-custom errors. This class can be used to check if an error
|
|
1298
1356
|
* is one of the standard kinds, allowing you to switch on the kind to further narrow the type.
|
|
@@ -1319,7 +1377,7 @@ declare class EmailValidationError extends BaseNgValidationError {
|
|
|
1319
1377
|
* @experimental 21.0.0
|
|
1320
1378
|
*/
|
|
1321
1379
|
declare const NgValidationError: abstract new () => NgValidationError;
|
|
1322
|
-
type NgValidationError = RequiredValidationError | MinValidationError | MaxValidationError | MinLengthValidationError | MaxLengthValidationError | PatternValidationError | EmailValidationError | StandardSchemaValidationError;
|
|
1380
|
+
type NgValidationError = RequiredValidationError | MinValidationError | MaxValidationError | MinLengthValidationError | MaxLengthValidationError | PatternValidationError | EmailValidationError | StandardSchemaValidationError | NativeInputParseError;
|
|
1323
1381
|
|
|
1324
1382
|
/**
|
|
1325
1383
|
* Configuration options for signal forms.
|
|
@@ -1339,24 +1397,6 @@ interface SignalFormsConfig {
|
|
|
1339
1397
|
*/
|
|
1340
1398
|
declare function provideSignalFormsConfig(config: SignalFormsConfig): Provider[];
|
|
1341
1399
|
|
|
1342
|
-
/**
|
|
1343
|
-
* Options that can be specified when submitting a form.
|
|
1344
|
-
*
|
|
1345
|
-
* @experimental 21.2.0
|
|
1346
|
-
*/
|
|
1347
|
-
interface FormSubmitOptions<TModel> {
|
|
1348
|
-
/** Function to run when submitting the form data (when form is valid). */
|
|
1349
|
-
action: (form: FieldTree<TModel>) => Promise<TreeValidationResult>;
|
|
1350
|
-
/** Function to run when attempting to submit the form data but validation is failing. */
|
|
1351
|
-
onInvalid?: (form: FieldTree<TModel>) => void;
|
|
1352
|
-
/**
|
|
1353
|
-
* Whether to ignore any of the validators when submitting:
|
|
1354
|
-
* - 'pending': Will submit if there are no invalid validators, pending validators do not block submission (default)
|
|
1355
|
-
* - 'none': Will not submit unless all validators are passing, pending validators block submission
|
|
1356
|
-
* - 'ignore': Will always submit regardless of invalid or pending validators
|
|
1357
|
-
*/
|
|
1358
|
-
ignoreValidators?: 'pending' | 'none' | 'all';
|
|
1359
|
-
}
|
|
1360
1400
|
/**
|
|
1361
1401
|
* Options that may be specified when creating a form.
|
|
1362
1402
|
*
|
|
@@ -1372,7 +1412,7 @@ interface FormOptions<TModel> {
|
|
|
1372
1412
|
/** The name of the root form, used in generating name attributes for the fields. */
|
|
1373
1413
|
name?: string;
|
|
1374
1414
|
/** Options that define how to handle form submission. */
|
|
1375
|
-
submission?: FormSubmitOptions<TModel>;
|
|
1415
|
+
submission?: FormSubmitOptions<TModel, unknown>;
|
|
1376
1416
|
}
|
|
1377
1417
|
/**
|
|
1378
1418
|
* Creates a form wrapped around the given model data. A form is represented as simply a `FieldTree`
|
|
@@ -1613,8 +1653,8 @@ declare function applyWhenValue<TValue>(path: SchemaPath<TValue>, predicate: (va
|
|
|
1613
1653
|
* @category submission
|
|
1614
1654
|
* @experimental 21.0.0
|
|
1615
1655
|
*/
|
|
1616
|
-
declare function submit<TModel>(form: FieldTree<TModel>, options?: FormSubmitOptions<TModel
|
|
1617
|
-
declare function submit<TModel>(form: FieldTree<TModel>, action: FormSubmitOptions<TModel>['action']): Promise<boolean>;
|
|
1656
|
+
declare function submit<TModel>(form: FieldTree<TModel>, options?: NoInfer<FormSubmitOptions<unknown, TModel>>): Promise<boolean>;
|
|
1657
|
+
declare function submit<TModel>(form: FieldTree<TModel>, action: NoInfer<FormSubmitOptions<unknown, TModel>['action']>): Promise<boolean>;
|
|
1618
1658
|
/**
|
|
1619
1659
|
* Creates a `Schema` that adds logic rules to a form.
|
|
1620
1660
|
* @param fn A **non-reactive** function that sets up reactive logic rules for the form.
|
|
@@ -1626,5 +1666,5 @@ declare function submit<TModel>(form: FieldTree<TModel>, action: FormSubmitOptio
|
|
|
1626
1666
|
*/
|
|
1627
1667
|
declare function schema<TValue>(fn: SchemaFn<TValue>): Schema<TValue>;
|
|
1628
1668
|
|
|
1629
|
-
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 };
|
|
1630
|
-
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 };
|
|
1669
|
+
export { BaseNgValidationError, EmailValidationError, FORM_FIELD, FormField, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MetadataReducer, MinLengthValidationError, MinValidationError, NativeInputParseError, 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 };
|
|
1670
|
+
export type { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, Debouncer, DisabledReason, Field, 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 };
|
package/types/forms.d.ts
CHANGED