@angular/forms 21.0.0-next.9 → 21.0.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/forms.mjs +4828 -7310
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals.mjs +1845 -3112
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +4 -4
- package/types/forms.d.ts +1 -1
- package/types/signals.d.ts +186 -149
package/types/signals.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.0.0-
|
|
2
|
+
* @license Angular v21.0.0-rc.0
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
@@ -44,6 +44,9 @@ declare class InteropNgControl implements Pick<NgControl, InteropSharedKeys | 'c
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Lightweight DI token provided by the {@link Field} directive.
|
|
47
|
+
*
|
|
48
|
+
* @category control
|
|
49
|
+
* @experimental 21.0.0
|
|
47
50
|
*/
|
|
48
51
|
declare const FIELD: InjectionToken<Field<unknown>>;
|
|
49
52
|
/**
|
|
@@ -87,119 +90,121 @@ declare class Field<T> implements _Control<T> {
|
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
/**
|
|
90
|
-
* Represents
|
|
91
|
-
* in the schema. A particular `
|
|
93
|
+
* Represents metadata that may be defined on a field when it is created using a `metadata` rule
|
|
94
|
+
* in the schema. A particular `MetadataKey` can only be defined on a particular field **once**.
|
|
92
95
|
*
|
|
93
96
|
* @category logic
|
|
94
97
|
* @experimental 21.0.0
|
|
95
98
|
*/
|
|
96
|
-
declare class
|
|
99
|
+
declare class MetadataKey<TValue> {
|
|
97
100
|
private brand;
|
|
98
|
-
/** Use {@link
|
|
101
|
+
/** Use {@link createMetadataKey}. */
|
|
99
102
|
private constructor();
|
|
100
103
|
}
|
|
101
104
|
/**
|
|
102
|
-
* Creates a {@link
|
|
105
|
+
* Creates a {@link MetadataKey}.
|
|
103
106
|
*
|
|
104
107
|
* @experimental 21.0.0
|
|
105
108
|
*/
|
|
106
|
-
declare function
|
|
109
|
+
declare function createMetadataKey<TValue>(): MetadataKey<TValue>;
|
|
107
110
|
/**
|
|
108
|
-
* Represents
|
|
111
|
+
* Represents metadata that is aggregated from multiple parts according to the key's reducer
|
|
109
112
|
* function. A value can be contributed to the aggregated value for a field using an
|
|
110
|
-
* `
|
|
111
|
-
* values to the same `
|
|
113
|
+
* `aggregateMetadata` rule in the schema. There may be multiple rules in a schema that contribute
|
|
114
|
+
* values to the same `AggregateMetadataKey` of the same field.
|
|
112
115
|
*
|
|
113
116
|
* @experimental 21.0.0
|
|
114
117
|
*/
|
|
115
|
-
declare class
|
|
118
|
+
declare class AggregateMetadataKey<TAcc, TItem> {
|
|
116
119
|
readonly reduce: (acc: TAcc, item: TItem) => TAcc;
|
|
117
120
|
readonly getInitial: () => TAcc;
|
|
118
121
|
private brand;
|
|
119
|
-
/** Use {@link
|
|
122
|
+
/** Use {@link reducedMetadataKey}. */
|
|
120
123
|
private constructor();
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
|
-
* Creates an
|
|
124
|
-
* the given `reduce` and `getInitial` functions.
|
|
126
|
+
* Creates an {@link AggregateMetadataKey} that reduces its individual values into an accumulated
|
|
127
|
+
* value using the given `reduce` and `getInitial` functions.
|
|
125
128
|
* @param reduce The reducer function.
|
|
126
129
|
* @param getInitial A function that gets the initial value for the reduce operation.
|
|
127
130
|
*
|
|
128
131
|
* @experimental 21.0.0
|
|
129
132
|
*/
|
|
130
|
-
declare function
|
|
133
|
+
declare function reducedMetadataKey<TAcc, TItem>(reduce: (acc: TAcc, item: TItem) => TAcc, getInitial: () => TAcc): AggregateMetadataKey<TAcc, TItem>;
|
|
131
134
|
/**
|
|
132
|
-
* Creates an
|
|
135
|
+
* Creates an {@link AggregateMetadataKey} that reduces its individual values into a list.
|
|
133
136
|
*
|
|
134
137
|
* @experimental 21.0.0
|
|
135
138
|
*/
|
|
136
|
-
declare function
|
|
139
|
+
declare function listMetadataKey<TItem>(): AggregateMetadataKey<TItem[], TItem | undefined>;
|
|
137
140
|
/**
|
|
138
|
-
* Creates
|
|
141
|
+
* Creates {@link AggregateMetadataKey} that reduces its individual values by taking their min.
|
|
139
142
|
*
|
|
140
143
|
* @experimental 21.0.0
|
|
141
144
|
*/
|
|
142
|
-
declare function
|
|
145
|
+
declare function minMetadataKey(): AggregateMetadataKey<number | undefined, number | undefined>;
|
|
143
146
|
/**
|
|
144
|
-
* Creates
|
|
147
|
+
* Creates {@link AggregateMetadataKey} that reduces its individual values by taking their max.
|
|
145
148
|
*
|
|
146
149
|
* @experimental 21.0.0
|
|
147
150
|
*/
|
|
148
|
-
declare function
|
|
151
|
+
declare function maxMetadataKey(): AggregateMetadataKey<number | undefined, number | undefined>;
|
|
149
152
|
/**
|
|
150
|
-
* Creates an
|
|
153
|
+
* Creates an {@link AggregateMetadataKey} that reduces its individual values by logically or-ing
|
|
154
|
+
* them.
|
|
151
155
|
*
|
|
152
156
|
* @experimental 21.0.0
|
|
153
157
|
*/
|
|
154
|
-
declare function
|
|
158
|
+
declare function orMetadataKey(): AggregateMetadataKey<boolean, boolean>;
|
|
155
159
|
/**
|
|
156
|
-
* Creates an
|
|
160
|
+
* Creates an {@link AggregateMetadataKey} that reduces its individual values by logically and-ing
|
|
161
|
+
* them.
|
|
157
162
|
*
|
|
158
163
|
* @experimental 21.0.0
|
|
159
164
|
*/
|
|
160
|
-
declare function
|
|
165
|
+
declare function andMetadataKey(): AggregateMetadataKey<boolean, boolean>;
|
|
161
166
|
/**
|
|
162
|
-
* An
|
|
167
|
+
* An {@link AggregateMetadataKey} representing whether the field is required.
|
|
163
168
|
*
|
|
164
169
|
* @category validation
|
|
165
170
|
* @experimental 21.0.0
|
|
166
171
|
*/
|
|
167
|
-
declare const REQUIRED:
|
|
172
|
+
declare const REQUIRED: AggregateMetadataKey<boolean, boolean>;
|
|
168
173
|
/**
|
|
169
|
-
* An
|
|
174
|
+
* An {@link AggregateMetadataKey} representing the min value of the field.
|
|
170
175
|
*
|
|
171
176
|
* @category validation
|
|
172
177
|
* @experimental 21.0.0
|
|
173
178
|
*/
|
|
174
|
-
declare const MIN:
|
|
179
|
+
declare const MIN: AggregateMetadataKey<number | undefined, number | undefined>;
|
|
175
180
|
/**
|
|
176
|
-
* An
|
|
181
|
+
* An {@link AggregateMetadataKey} representing the max value of the field.
|
|
177
182
|
*
|
|
178
183
|
* @category validation
|
|
179
184
|
* @experimental 21.0.0
|
|
180
185
|
*/
|
|
181
|
-
declare const MAX:
|
|
186
|
+
declare const MAX: AggregateMetadataKey<number | undefined, number | undefined>;
|
|
182
187
|
/**
|
|
183
|
-
* An
|
|
188
|
+
* An {@link AggregateMetadataKey} representing the min length of the field.
|
|
184
189
|
*
|
|
185
190
|
* @category validation
|
|
186
191
|
* @experimental 21.0.0
|
|
187
192
|
*/
|
|
188
|
-
declare const MIN_LENGTH:
|
|
193
|
+
declare const MIN_LENGTH: AggregateMetadataKey<number | undefined, number | undefined>;
|
|
189
194
|
/**
|
|
190
|
-
* An
|
|
195
|
+
* An {@link AggregateMetadataKey} representing the max length of the field.
|
|
191
196
|
*
|
|
192
197
|
* @category validation
|
|
193
198
|
* @experimental 21.0.0
|
|
194
199
|
*/
|
|
195
|
-
declare const MAX_LENGTH:
|
|
200
|
+
declare const MAX_LENGTH: AggregateMetadataKey<number | undefined, number | undefined>;
|
|
196
201
|
/**
|
|
197
|
-
* An
|
|
202
|
+
* An {@link AggregateMetadataKey} representing the patterns the field must match.
|
|
198
203
|
*
|
|
199
204
|
* @category validation
|
|
200
205
|
* @experimental 21.0.0
|
|
201
206
|
*/
|
|
202
|
-
declare const PATTERN:
|
|
207
|
+
declare const PATTERN: AggregateMetadataKey<RegExp[], RegExp | undefined>;
|
|
203
208
|
|
|
204
209
|
/**
|
|
205
210
|
* Options used to create a `ValidationError`.
|
|
@@ -381,7 +386,7 @@ declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: Va
|
|
|
381
386
|
* @category validation
|
|
382
387
|
* @experimental 21.0.0
|
|
383
388
|
*/
|
|
384
|
-
declare function customError<E extends Partial<
|
|
389
|
+
declare function customError<E extends Partial<ValidationErrorWithField>>(obj: WithField<E>): CustomValidationError;
|
|
385
390
|
/**
|
|
386
391
|
* Create a custom error
|
|
387
392
|
* @param obj The object to create an error from
|
|
@@ -389,11 +394,14 @@ declare function customError<E extends Partial<ValidationError>>(obj: WithField<
|
|
|
389
394
|
* @category validation
|
|
390
395
|
* @experimental 21.0.0
|
|
391
396
|
*/
|
|
392
|
-
declare function customError<E extends Partial<
|
|
397
|
+
declare function customError<E extends Partial<ValidationErrorWithField>>(obj?: E): WithoutField<CustomValidationError>;
|
|
393
398
|
/**
|
|
394
399
|
* Common interface for all validation errors.
|
|
395
400
|
*
|
|
396
|
-
*
|
|
401
|
+
* This can be returned from validators.
|
|
402
|
+
*
|
|
403
|
+
* It's also used by the creation functions to create an instance
|
|
404
|
+
* (e.g. `requiredError`, `minError`, etc.).
|
|
397
405
|
*
|
|
398
406
|
* @category validation
|
|
399
407
|
* @experimental 21.0.0
|
|
@@ -401,11 +409,38 @@ declare function customError<E extends Partial<ValidationError>>(obj?: E): Witho
|
|
|
401
409
|
interface ValidationError {
|
|
402
410
|
/** Identifies the kind of error. */
|
|
403
411
|
readonly kind: string;
|
|
404
|
-
/** The field associated with this error. */
|
|
405
|
-
readonly field: FieldTree<unknown>;
|
|
406
412
|
/** Human readable error message. */
|
|
407
413
|
readonly message?: string;
|
|
408
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Validation error with a field.
|
|
417
|
+
*
|
|
418
|
+
* This is returned from field state, e.g., catField.errors() would be of a list of errors with
|
|
419
|
+
* `field: catField` bound to state.
|
|
420
|
+
*/
|
|
421
|
+
interface ValidationErrorWithField extends ValidationError {
|
|
422
|
+
/** The field associated with this error. */
|
|
423
|
+
readonly field: FieldTree<unknown>;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Validation error with optional field.
|
|
427
|
+
*
|
|
428
|
+
* This is generally used in places where the result might have a field.
|
|
429
|
+
* e.g., as a result of a `validateTree`, or when handling form submission.
|
|
430
|
+
*/
|
|
431
|
+
interface ValidationErrorWithOptionalField extends ValidationError {
|
|
432
|
+
/** The field associated with this error. */
|
|
433
|
+
readonly field?: FieldTree<unknown>;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Validation error with no field.
|
|
437
|
+
*
|
|
438
|
+
* This is used to strongly enforce that fields are not allowed in validation result.
|
|
439
|
+
*/
|
|
440
|
+
interface ValidationErrorWithoutField extends ValidationError {
|
|
441
|
+
/** The field associated with this error. */
|
|
442
|
+
readonly field?: never;
|
|
443
|
+
}
|
|
409
444
|
/**
|
|
410
445
|
* A custom error that may contain additional properties
|
|
411
446
|
*
|
|
@@ -624,21 +659,6 @@ interface DisabledReason {
|
|
|
624
659
|
* @experimental 21.0.0
|
|
625
660
|
*/
|
|
626
661
|
type ValidationSuccess = null | undefined | void;
|
|
627
|
-
/**
|
|
628
|
-
* The result of running a field validation function.
|
|
629
|
-
*
|
|
630
|
-
* The result may be one of the following:
|
|
631
|
-
* 1. A {@link ValidationSuccess} to indicate no errors.
|
|
632
|
-
* 2. A {@link ValidationError} without a field to indicate an error on the field being validated.
|
|
633
|
-
* 3. A list of {@link ValidationError} without fields to indicate multiple errors on the field
|
|
634
|
-
* being validated.
|
|
635
|
-
*
|
|
636
|
-
* @template E the type of error (defaults to {@link ValidationError}).
|
|
637
|
-
*
|
|
638
|
-
* @category types
|
|
639
|
-
* @experimental 21.0.0
|
|
640
|
-
*/
|
|
641
|
-
type FieldValidationResult<E extends ValidationError = ValidationError> = ValidationSuccess | OneOrMany<WithoutField<E>>;
|
|
642
662
|
/**
|
|
643
663
|
* The result of running a tree validation function.
|
|
644
664
|
*
|
|
@@ -653,7 +673,7 @@ type FieldValidationResult<E extends ValidationError = ValidationError> = Valida
|
|
|
653
673
|
* @category types
|
|
654
674
|
* @experimental 21.0.0
|
|
655
675
|
*/
|
|
656
|
-
type TreeValidationResult<E extends
|
|
676
|
+
type TreeValidationResult<E extends ValidationErrorWithOptionalField = ValidationErrorWithOptionalField> = ValidationSuccess | OneOrMany<E>;
|
|
657
677
|
/**
|
|
658
678
|
* A validation result where all errors explicitly define their target field.
|
|
659
679
|
*
|
|
@@ -752,11 +772,11 @@ interface FieldState<TValue, TKey extends string | number = string | number> ext
|
|
|
752
772
|
*/
|
|
753
773
|
readonly hidden: Signal<boolean>;
|
|
754
774
|
readonly disabledReasons: Signal<readonly DisabledReason[]>;
|
|
755
|
-
readonly errors: Signal<
|
|
775
|
+
readonly errors: Signal<ValidationErrorWithField[]>;
|
|
756
776
|
/**
|
|
757
777
|
* A signal containing the {@link errors} of the field and its descendants.
|
|
758
778
|
*/
|
|
759
|
-
readonly errorSummary: Signal<
|
|
779
|
+
readonly errorSummary: Signal<ValidationErrorWithField[]>;
|
|
760
780
|
/**
|
|
761
781
|
* A signal indicating whether the field's value is currently valid.
|
|
762
782
|
*
|
|
@@ -799,19 +819,19 @@ interface FieldState<TValue, TKey extends string | number = string | number> ext
|
|
|
799
819
|
*/
|
|
800
820
|
readonly fieldBindings: Signal<readonly Field<unknown>[]>;
|
|
801
821
|
/**
|
|
802
|
-
* Reads an aggregate
|
|
803
|
-
* @param
|
|
822
|
+
* Reads an aggregate metadata value from the field.
|
|
823
|
+
* @param key The metadata key to read.
|
|
804
824
|
*/
|
|
805
|
-
|
|
825
|
+
metadata<M>(key: AggregateMetadataKey<M, any>): Signal<M>;
|
|
806
826
|
/**
|
|
807
|
-
* Reads a
|
|
808
|
-
* @param
|
|
827
|
+
* Reads a metadata value from the field.
|
|
828
|
+
* @param key The metadata key to read.
|
|
809
829
|
*/
|
|
810
|
-
|
|
830
|
+
metadata<M>(key: MetadataKey<M>): M | undefined;
|
|
811
831
|
/**
|
|
812
832
|
* Checks whether the given metadata key has been defined for this field.
|
|
813
833
|
*/
|
|
814
|
-
|
|
834
|
+
hasMetadata(key: MetadataKey<any> | AggregateMetadataKey<any, any>): boolean;
|
|
815
835
|
/**
|
|
816
836
|
* Resets the {@link touched} and {@link dirty} state of the field and its descendants.
|
|
817
837
|
*
|
|
@@ -901,7 +921,7 @@ type LogicFn<TValue, TReturn, TPathKind extends PathKind = PathKind.Root> = (ctx
|
|
|
901
921
|
* @category validation
|
|
902
922
|
* @experimental 21.0.0
|
|
903
923
|
*/
|
|
904
|
-
type FieldValidator<TValue, TPathKind extends PathKind = PathKind.Root> = LogicFn<TValue,
|
|
924
|
+
type FieldValidator<TValue, TPathKind extends PathKind = PathKind.Root> = LogicFn<TValue, ValidationResult<ValidationErrorWithoutField>, TPathKind>;
|
|
905
925
|
/**
|
|
906
926
|
* A function that takes the `FieldContext` for the field being validated and returns a
|
|
907
927
|
* `TreeValidationResult` indicating errors for the field and its sub-fields.
|
|
@@ -1018,6 +1038,11 @@ interface AsyncValidatorOptions<TValue, TParams, TResult, TPathKind extends Path
|
|
|
1018
1038
|
* @returns A reference to the constructed resource.
|
|
1019
1039
|
*/
|
|
1020
1040
|
readonly factory: (params: Signal<TParams | undefined>) => ResourceRef<TResult | undefined>;
|
|
1041
|
+
/**
|
|
1042
|
+
* A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
|
|
1043
|
+
* Receives the error and the field context, returns a list of validation errors.
|
|
1044
|
+
*/
|
|
1045
|
+
readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
|
|
1021
1046
|
/**
|
|
1022
1047
|
* A function that takes the resource result, and the current field context and maps it to a list
|
|
1023
1048
|
* of validation errors.
|
|
@@ -1029,7 +1054,7 @@ interface AsyncValidatorOptions<TValue, TParams, TResult, TPathKind extends Path
|
|
|
1029
1054
|
* A targeted error will show up as an error on its target field rather than the field being validated.
|
|
1030
1055
|
* If a field is not given, the error is assumed to apply to the field being validated.
|
|
1031
1056
|
*/
|
|
1032
|
-
readonly
|
|
1057
|
+
readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
|
|
1033
1058
|
}
|
|
1034
1059
|
/**
|
|
1035
1060
|
* Options that indicate how to create an httpResource for async validation for a field,
|
|
@@ -1062,7 +1087,12 @@ interface HttpValidatorOptions<TValue, TResult, TPathKind extends PathKind = Pat
|
|
|
1062
1087
|
* A targeted error will show up as an error on its target field rather than the field being validated.
|
|
1063
1088
|
* If a field is not given, the error is assumed to apply to the field being validated.
|
|
1064
1089
|
*/
|
|
1065
|
-
readonly
|
|
1090
|
+
readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
|
|
1091
|
+
/**
|
|
1092
|
+
* A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
|
|
1093
|
+
* Receives the error and the field context, returns a list of validation errors.
|
|
1094
|
+
*/
|
|
1095
|
+
readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
|
|
1066
1096
|
/**
|
|
1067
1097
|
* The options to use when creating the httpResource.
|
|
1068
1098
|
*/
|
|
@@ -1311,44 +1341,44 @@ declare function validate<TValue, TPathKind extends PathKind = PathKind.Root>(pa
|
|
|
1311
1341
|
*/
|
|
1312
1342
|
declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root>(path: FieldPath<TValue, TPathKind>, logic: NoInfer<TreeValidator<TValue, TPathKind>>): void;
|
|
1313
1343
|
/**
|
|
1314
|
-
* Adds a value to an
|
|
1344
|
+
* Adds a value to an {@link AggregateMetadataKey} of a field.
|
|
1315
1345
|
*
|
|
1316
|
-
* @param path The target path to set the aggregate
|
|
1317
|
-
* @param
|
|
1318
|
-
* @param logic A function that receives the `FieldContext` and returns a value to add to the aggregate
|
|
1346
|
+
* @param path The target path to set the aggregate metadata on.
|
|
1347
|
+
* @param key The aggregate metadata key
|
|
1348
|
+
* @param logic A function that receives the `FieldContext` and returns a value to add to the aggregate metadata.
|
|
1319
1349
|
* @template TValue The type of value stored in the field the logic is bound to.
|
|
1320
|
-
* @template
|
|
1350
|
+
* @template TMetadataItem The type of value the metadata aggregates over.
|
|
1321
1351
|
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
1322
1352
|
*
|
|
1323
1353
|
* @category logic
|
|
1324
1354
|
* @experimental 21.0.0
|
|
1325
1355
|
*/
|
|
1326
|
-
declare function
|
|
1356
|
+
declare function aggregateMetadata<TValue, TMetadataItem, TPathKind extends PathKind = PathKind.Root>(path: FieldPath<TValue, TPathKind>, key: AggregateMetadataKey<any, TMetadataItem>, logic: NoInfer<LogicFn<TValue, TMetadataItem, TPathKind>>): void;
|
|
1327
1357
|
/**
|
|
1328
|
-
* Creates a new
|
|
1358
|
+
* Creates a new {@link MetadataKey} and defines the value of the new metadata key for the given field.
|
|
1329
1359
|
*
|
|
1330
|
-
* @param path The path to define the
|
|
1331
|
-
* @param factory A factory function that creates the value for the
|
|
1360
|
+
* @param path The path to define the metadata for.
|
|
1361
|
+
* @param factory A factory function that creates the value for the metadata.
|
|
1332
1362
|
* This function is **not** reactive. It is run once when the field is created.
|
|
1333
|
-
* @returns The newly created
|
|
1363
|
+
* @returns The newly created metadata key
|
|
1334
1364
|
*
|
|
1335
1365
|
* @category logic
|
|
1336
1366
|
* @experimental 21.0.0
|
|
1337
1367
|
*/
|
|
1338
|
-
declare function
|
|
1368
|
+
declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path: FieldPath<TValue, TPathKind>, factory: (ctx: FieldContext<TValue, TPathKind>) => TData): MetadataKey<TData>;
|
|
1339
1369
|
/**
|
|
1340
|
-
* Defines the value of a
|
|
1370
|
+
* Defines the value of a {@link MetadataKey} for a given field.
|
|
1341
1371
|
*
|
|
1342
|
-
* @param path The path to define the
|
|
1343
|
-
* @param
|
|
1344
|
-
* @param factory A factory function that creates the value for the
|
|
1372
|
+
* @param path The path to define the metadata for.
|
|
1373
|
+
* @param key The metadata key to define.
|
|
1374
|
+
* @param factory A factory function that creates the value for the metadata.
|
|
1345
1375
|
* This function is **not** reactive. It is run once when the field is created.
|
|
1346
|
-
* @returns The given
|
|
1376
|
+
* @returns The given metadata key
|
|
1347
1377
|
*
|
|
1348
1378
|
* @category logic
|
|
1349
1379
|
* @experimental 21.0.0
|
|
1350
1380
|
*/
|
|
1351
|
-
declare function
|
|
1381
|
+
declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path: FieldPath<TValue, TPathKind>, key: MetadataKey<TData>, factory: (ctx: FieldContext<TValue, TPathKind>) => TData): MetadataKey<TData>;
|
|
1352
1382
|
|
|
1353
1383
|
/** Represents a result that should be ignored because its predicate indicates it is not active. */
|
|
1354
1384
|
declare const IGNORED: unique symbol;
|
|
@@ -1462,46 +1492,46 @@ declare class LogicContainer {
|
|
|
1462
1492
|
/** Logic that determines if the field is read-only. */
|
|
1463
1493
|
readonly readonly: BooleanOrLogic;
|
|
1464
1494
|
/** Logic that produces synchronous validation errors for the field. */
|
|
1465
|
-
readonly syncErrors: ArrayMergeIgnoreLogic<
|
|
1495
|
+
readonly syncErrors: ArrayMergeIgnoreLogic<ValidationErrorWithField, null>;
|
|
1466
1496
|
/** Logic that produces synchronous validation errors for the field's subtree. */
|
|
1467
|
-
readonly syncTreeErrors: ArrayMergeIgnoreLogic<
|
|
1497
|
+
readonly syncTreeErrors: ArrayMergeIgnoreLogic<ValidationErrorWithField, null>;
|
|
1468
1498
|
/** Logic that produces asynchronous validation results (errors or 'pending'). */
|
|
1469
|
-
readonly asyncErrors: ArrayMergeIgnoreLogic<
|
|
1470
|
-
/** A map of aggregate
|
|
1471
|
-
private readonly
|
|
1472
|
-
/** A map of
|
|
1473
|
-
private readonly
|
|
1499
|
+
readonly asyncErrors: ArrayMergeIgnoreLogic<ValidationErrorWithField | 'pending', null>;
|
|
1500
|
+
/** A map of aggregate metadata keys to the `AbstractLogic` instances that compute their values. */
|
|
1501
|
+
private readonly aggregateMetadataKeys;
|
|
1502
|
+
/** A map of metadata keys to the factory functions that create their values. */
|
|
1503
|
+
private readonly metadataFactories;
|
|
1474
1504
|
/**
|
|
1475
1505
|
* Constructs a new `Logic` container.
|
|
1476
1506
|
* @param predicates An array of predicates that must all be true for the logic
|
|
1477
1507
|
* functions within this container to be active.
|
|
1478
1508
|
*/
|
|
1479
1509
|
constructor(predicates: ReadonlyArray<BoundPredicate>);
|
|
1480
|
-
/** Checks whether there is logic for the given aggregate
|
|
1481
|
-
|
|
1510
|
+
/** Checks whether there is logic for the given aggregate metadata key. */
|
|
1511
|
+
hasAggregateMetadata(key: AggregateMetadataKey<any, any>): boolean;
|
|
1482
1512
|
/**
|
|
1483
|
-
* Gets an iterable of [aggregate
|
|
1484
|
-
* @returns An iterable of aggregate
|
|
1513
|
+
* Gets an iterable of [aggregate metadata, logic function] pairs.
|
|
1514
|
+
* @returns An iterable of aggregate metadata entries.
|
|
1485
1515
|
*/
|
|
1486
|
-
|
|
1516
|
+
getAggregateMetadataEntries(): MapIterator<[AggregateMetadataKey<unknown, unknown>, AbstractLogic<unknown, unknown>]>;
|
|
1487
1517
|
/**
|
|
1488
|
-
* Gets an iterable of [
|
|
1489
|
-
* @returns An iterable of
|
|
1518
|
+
* Gets an iterable of [metadata, value factory function] pairs.
|
|
1519
|
+
* @returns An iterable of metadata factory entries.
|
|
1490
1520
|
*/
|
|
1491
|
-
|
|
1521
|
+
getMetadataFactoryEntries(): MapIterator<[MetadataKey<unknown>, (ctx: FieldContext<unknown>) => unknown]>;
|
|
1492
1522
|
/**
|
|
1493
|
-
* Retrieves or creates the `AbstractLogic` for a given aggregate
|
|
1494
|
-
* @param
|
|
1523
|
+
* Retrieves or creates the `AbstractLogic` for a given aggregate metadata key.
|
|
1524
|
+
* @param key The `AggregateMetadataKey` for which to get the logic.
|
|
1495
1525
|
* @returns The `AbstractLogic` associated with the key.
|
|
1496
1526
|
*/
|
|
1497
|
-
|
|
1527
|
+
getAggregateMetadata<T>(key: AggregateMetadataKey<unknown, T>): AbstractLogic<T>;
|
|
1498
1528
|
/**
|
|
1499
|
-
* Adds a factory function for a given
|
|
1500
|
-
* @param
|
|
1529
|
+
* Adds a factory function for a given metadata key.
|
|
1530
|
+
* @param key The `MetadataKey` to associate the factory with.
|
|
1501
1531
|
* @param factory The factory function.
|
|
1502
1532
|
* @throws If a factory is already defined for the given key.
|
|
1503
1533
|
*/
|
|
1504
|
-
|
|
1534
|
+
addMetadataFactory(key: MetadataKey<unknown>, factory: (ctx: FieldContext<unknown>) => unknown): void;
|
|
1505
1535
|
/**
|
|
1506
1536
|
* Merges logic from another `Logic` instance into this one.
|
|
1507
1537
|
* @param other The `Logic` instance to merge from.
|
|
@@ -1533,10 +1563,10 @@ declare abstract class AbstractLogicNodeBuilder {
|
|
|
1533
1563
|
abstract addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult>): void;
|
|
1534
1564
|
/** Adds a rule for asynchronous validation errors for a field. */
|
|
1535
1565
|
abstract addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult>): void;
|
|
1536
|
-
/** Adds a rule to compute
|
|
1537
|
-
abstract
|
|
1566
|
+
/** Adds a rule to compute aggregate metadata for a field. */
|
|
1567
|
+
abstract addAggregateMetadataRule<M>(key: AggregateMetadataKey<unknown, M>, logic: LogicFn<any, M>): void;
|
|
1538
1568
|
/** Adds a factory function to produce a data value associated with a field. */
|
|
1539
|
-
abstract
|
|
1569
|
+
abstract addMetadataFactory<D>(key: MetadataKey<D>, factory: (ctx: FieldContext<any>) => D): void;
|
|
1540
1570
|
/**
|
|
1541
1571
|
* Gets a builder for a child node associated with the given property key.
|
|
1542
1572
|
* @param key The property key of the child.
|
|
@@ -1579,11 +1609,11 @@ declare class LogicNodeBuilder extends AbstractLogicNodeBuilder {
|
|
|
1579
1609
|
addHiddenRule(logic: LogicFn<any, boolean>): void;
|
|
1580
1610
|
addDisabledReasonRule(logic: LogicFn<any, DisabledReason | undefined>): void;
|
|
1581
1611
|
addReadonlyRule(logic: LogicFn<any, boolean>): void;
|
|
1582
|
-
addSyncErrorRule(logic: LogicFn<any, ValidationResult
|
|
1583
|
-
addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult
|
|
1584
|
-
addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult
|
|
1585
|
-
|
|
1586
|
-
|
|
1612
|
+
addSyncErrorRule(logic: LogicFn<any, ValidationResult<ValidationErrorWithField>>): void;
|
|
1613
|
+
addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult<ValidationErrorWithField>>): void;
|
|
1614
|
+
addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult<ValidationErrorWithField>>): void;
|
|
1615
|
+
addAggregateMetadataRule<T>(key: AggregateMetadataKey<unknown, T>, logic: LogicFn<any, T>): void;
|
|
1616
|
+
addMetadataFactory<D>(key: MetadataKey<D>, factory: (ctx: FieldContext<any>) => D): void;
|
|
1587
1617
|
getChild(key: PropertyKey): LogicNodeBuilder;
|
|
1588
1618
|
hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
1589
1619
|
/**
|
|
@@ -1661,8 +1691,10 @@ declare class SchemaImpl {
|
|
|
1661
1691
|
declare class FieldPathNode {
|
|
1662
1692
|
/** The property keys used to navigate from the root path to this path. */
|
|
1663
1693
|
readonly keys: PropertyKey[];
|
|
1664
|
-
/** The
|
|
1665
|
-
readonly
|
|
1694
|
+
/** The parent of this path node. */
|
|
1695
|
+
private readonly parent;
|
|
1696
|
+
/** The key of this node in its parent. */
|
|
1697
|
+
private readonly keyInParent;
|
|
1666
1698
|
/** The root path node from which this path node is descended. */
|
|
1667
1699
|
readonly root: FieldPathNode;
|
|
1668
1700
|
/**
|
|
@@ -1674,11 +1706,20 @@ declare class FieldPathNode {
|
|
|
1674
1706
|
* A proxy that wraps the path node, allowing navigation to its child paths via property access.
|
|
1675
1707
|
*/
|
|
1676
1708
|
readonly fieldPathProxy: FieldPath<any>;
|
|
1709
|
+
/**
|
|
1710
|
+
* For a root path node this will contain the root logic builder. For non-root nodes,
|
|
1711
|
+
* they determine their logic builder from their parent so this is undefined.
|
|
1712
|
+
*/
|
|
1713
|
+
private readonly logicBuilder;
|
|
1677
1714
|
protected constructor(
|
|
1678
1715
|
/** The property keys used to navigate from the root path to this path. */
|
|
1679
|
-
keys: PropertyKey[],
|
|
1716
|
+
keys: PropertyKey[], root: FieldPathNode | undefined,
|
|
1717
|
+
/** The parent of this path node. */
|
|
1718
|
+
parent: FieldPathNode | undefined,
|
|
1719
|
+
/** The key of this node in its parent. */
|
|
1720
|
+
keyInParent: PropertyKey | undefined);
|
|
1680
1721
|
/** The logic builder used to accumulate logic on this path node. */
|
|
1681
|
-
|
|
1722
|
+
get builder(): LogicNodeBuilder;
|
|
1682
1723
|
/**
|
|
1683
1724
|
* Gets the special path node containing the per-element logic that applies to *all* children paths.
|
|
1684
1725
|
*/
|
|
@@ -1701,21 +1742,17 @@ declare class FieldPathNode {
|
|
|
1701
1742
|
}
|
|
1702
1743
|
|
|
1703
1744
|
/**
|
|
1704
|
-
* Tracks custom
|
|
1745
|
+
* Tracks custom metadata associated with a `FieldNode`.
|
|
1705
1746
|
*/
|
|
1706
|
-
declare class
|
|
1747
|
+
declare class FieldMetadataState {
|
|
1707
1748
|
private readonly node;
|
|
1708
|
-
/** A map of all `
|
|
1709
|
-
private readonly
|
|
1749
|
+
/** A map of all `MetadataKey` and `AggregateMetadataKey` that have been defined for this field. */
|
|
1750
|
+
private readonly metadata;
|
|
1710
1751
|
constructor(node: FieldNode);
|
|
1711
|
-
/** Gets the value of a `
|
|
1712
|
-
get<T>(
|
|
1713
|
-
/**
|
|
1714
|
-
|
|
1715
|
-
* @param prop
|
|
1716
|
-
* @returns
|
|
1717
|
-
*/
|
|
1718
|
-
has(prop: Property<any> | AggregateProperty<any, any>): boolean;
|
|
1752
|
+
/** Gets the value of a `MetadataKey` or `AggregateMetadataKey` for the field. */
|
|
1753
|
+
get<T>(key: MetadataKey<T> | AggregateMetadataKey<T, unknown>): T | undefined | Signal<T>;
|
|
1754
|
+
/** Checks whether the current metadata state has the given metadata key. */
|
|
1755
|
+
has(key: MetadataKey<any> | AggregateMetadataKey<any, any>): boolean;
|
|
1719
1756
|
}
|
|
1720
1757
|
|
|
1721
1758
|
/**
|
|
@@ -1826,7 +1863,7 @@ declare class FieldSubmitState {
|
|
|
1826
1863
|
*/
|
|
1827
1864
|
readonly selfSubmitting: WritableSignal<boolean>;
|
|
1828
1865
|
/** Server errors that are associated with this field. */
|
|
1829
|
-
readonly serverErrors: WritableSignal<readonly
|
|
1866
|
+
readonly serverErrors: WritableSignal<readonly ValidationErrorWithField[]>;
|
|
1830
1867
|
constructor(node: FieldNode);
|
|
1831
1868
|
/**
|
|
1832
1869
|
* Whether this form is currently in the process of being submitted.
|
|
@@ -1840,14 +1877,14 @@ interface ValidationState {
|
|
|
1840
1877
|
* The full set of synchronous tree errors visible to this field. This includes ones that are
|
|
1841
1878
|
* targeted at a descendant field rather than at this field.
|
|
1842
1879
|
*/
|
|
1843
|
-
rawSyncTreeErrors: Signal<
|
|
1880
|
+
rawSyncTreeErrors: Signal<ValidationErrorWithField[]>;
|
|
1844
1881
|
/**
|
|
1845
1882
|
* The full set of synchronous errors for this field, including synchronous tree errors and server
|
|
1846
1883
|
* errors. Server errors are considered "synchronous" because they are imperatively added. From
|
|
1847
1884
|
* the perspective of the field state they are either there or not, they are never in a pending
|
|
1848
1885
|
* state.
|
|
1849
1886
|
*/
|
|
1850
|
-
syncErrors: Signal<
|
|
1887
|
+
syncErrors: Signal<ValidationErrorWithField[]>;
|
|
1851
1888
|
/**
|
|
1852
1889
|
* Whether the field is considered valid according solely to its synchronous validators.
|
|
1853
1890
|
* Errors resulting from a previous submit attempt are also considered for this state.
|
|
@@ -1858,21 +1895,21 @@ interface ValidationState {
|
|
|
1858
1895
|
* targeted at a descendant field rather than at this field, as well as sentinel 'pending' values
|
|
1859
1896
|
* indicating that the validator is still running and an error could still occur.
|
|
1860
1897
|
*/
|
|
1861
|
-
rawAsyncErrors: Signal<(
|
|
1898
|
+
rawAsyncErrors: Signal<(ValidationErrorWithField | 'pending')[]>;
|
|
1862
1899
|
/**
|
|
1863
1900
|
* The asynchronous tree errors visible to this field that are specifically targeted at this field
|
|
1864
1901
|
* rather than a descendant. This also includes all 'pending' sentinel values, since those could
|
|
1865
1902
|
* theoretically result in errors for this field.
|
|
1866
1903
|
*/
|
|
1867
|
-
asyncErrors: Signal<(
|
|
1904
|
+
asyncErrors: Signal<(ValidationErrorWithField | 'pending')[]>;
|
|
1868
1905
|
/**
|
|
1869
1906
|
* The combined set of all errors that currently apply to this field.
|
|
1870
1907
|
*/
|
|
1871
|
-
errors: Signal<
|
|
1908
|
+
errors: Signal<ValidationErrorWithField[]>;
|
|
1872
1909
|
/**
|
|
1873
1910
|
* The combined set of all errors that currently apply to this field and its descendants.
|
|
1874
1911
|
*/
|
|
1875
|
-
errorSummary: Signal<
|
|
1912
|
+
errorSummary: Signal<ValidationErrorWithField[]>;
|
|
1876
1913
|
/**
|
|
1877
1914
|
* Whether this field has any asynchronous validators still pending.
|
|
1878
1915
|
*/
|
|
@@ -1940,7 +1977,7 @@ interface ValidationState {
|
|
|
1940
1977
|
declare class FieldNode implements FieldState<unknown> {
|
|
1941
1978
|
readonly structure: FieldNodeStructure;
|
|
1942
1979
|
readonly validationState: ValidationState;
|
|
1943
|
-
readonly
|
|
1980
|
+
readonly metadataState: FieldMetadataState;
|
|
1944
1981
|
readonly nodeState: FieldNodeState;
|
|
1945
1982
|
readonly submitState: FieldSubmitState;
|
|
1946
1983
|
private _context;
|
|
@@ -1954,8 +1991,8 @@ declare class FieldNode implements FieldState<unknown> {
|
|
|
1954
1991
|
get logicNode(): LogicNode;
|
|
1955
1992
|
get value(): WritableSignal<unknown>;
|
|
1956
1993
|
get keyInParent(): Signal<string | number>;
|
|
1957
|
-
get errors(): Signal<
|
|
1958
|
-
get errorSummary(): Signal<
|
|
1994
|
+
get errors(): Signal<ValidationErrorWithField[]>;
|
|
1995
|
+
get errorSummary(): Signal<ValidationErrorWithField[]>;
|
|
1959
1996
|
get pending(): Signal<boolean>;
|
|
1960
1997
|
get valid(): Signal<boolean>;
|
|
1961
1998
|
get invalid(): Signal<boolean>;
|
|
@@ -1968,16 +2005,16 @@ declare class FieldNode implements FieldState<unknown> {
|
|
|
1968
2005
|
get fieldBindings(): Signal<readonly Field<unknown>[]>;
|
|
1969
2006
|
get submitting(): Signal<boolean>;
|
|
1970
2007
|
get name(): Signal<string>;
|
|
1971
|
-
private
|
|
2008
|
+
private metadataOrUndefined;
|
|
1972
2009
|
get max(): Signal<number | undefined> | undefined;
|
|
1973
2010
|
get maxLength(): Signal<number | undefined> | undefined;
|
|
1974
2011
|
get min(): Signal<number | undefined> | undefined;
|
|
1975
2012
|
get minLength(): Signal<number | undefined> | undefined;
|
|
1976
2013
|
get pattern(): Signal<readonly RegExp[]> | undefined;
|
|
1977
2014
|
get required(): Signal<boolean> | undefined;
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2015
|
+
metadata<M>(key: AggregateMetadataKey<M, any>): Signal<M>;
|
|
2016
|
+
metadata<M>(key: MetadataKey<M>): M | undefined;
|
|
2017
|
+
hasMetadata(key: MetadataKey<any> | AggregateMetadataKey<any, any>): boolean;
|
|
1981
2018
|
/**
|
|
1982
2019
|
* Marks this specific field as touched.
|
|
1983
2020
|
*/
|
|
@@ -2519,7 +2556,7 @@ type BaseValidatorConfig<TValue, TPathKind extends PathKind = PathKind.Root> = {
|
|
|
2519
2556
|
* Custom validation error(s) to report instead of the default,
|
|
2520
2557
|
* or a function that receives the `FieldContext` and returns custom validation error(s).
|
|
2521
2558
|
*/
|
|
2522
|
-
error?: OneOrMany<
|
|
2559
|
+
error?: OneOrMany<ValidationError> | LogicFn<TValue, OneOrMany<ValidationError>, TPathKind>;
|
|
2523
2560
|
message?: never;
|
|
2524
2561
|
};
|
|
2525
2562
|
|
|
@@ -2684,5 +2721,5 @@ type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
|
|
|
2684
2721
|
*/
|
|
2685
2722
|
declare function validateStandardSchema<TSchema, TValue extends IgnoreUnknownProperties<TSchema>>(path: FieldPath<TValue>, schema: StandardSchemaV1<TSchema>): void;
|
|
2686
2723
|
|
|
2687
|
-
export {
|
|
2688
|
-
export type { AsyncValidationResult, AsyncValidatorOptions, ChildFieldContext, DisabledReason, FieldContext, FieldPath, FieldState, FieldTree,
|
|
2724
|
+
export { AggregateMetadataKey, CustomValidationError, EmailValidationError, FIELD, Field, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PathKind, PatternValidationError, REQUIRED, RequiredValidationError, StandardSchemaValidationError, aggregateMetadata, andMetadataKey, apply, applyEach, applyWhen, applyWhenValue, createMetadataKey, customError, disabled, email, emailError, form, hidden, listMetadataKey, max, maxError, maxLength, maxLengthError, maxMetadataKey, metadata, min, minError, minLength, minLengthError, minMetadataKey, orMetadataKey, pattern, patternError, readonly, reducedMetadataKey, required, requiredError, schema, standardSchemaError, submit, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
|
|
2725
|
+
export type { AsyncValidationResult, AsyncValidatorOptions, ChildFieldContext, DisabledReason, FieldContext, FieldPath, FieldState, FieldTree, FieldValidator, FormCheckboxControl, FormOptions, FormUiControl, FormValueControl, HttpValidatorOptions, IgnoreUnknownProperties, ItemFieldContext, LogicFn, MapToErrorsFn, MaybeFieldPath, MaybeFieldTree, OneOrMany, ReadonlyArrayLike, RemoveStringIndexUnknownKey, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, Subfields, SubmittedStatus, TreeValidationResult, TreeValidator, ValidationError, ValidationErrorWithField, ValidationErrorWithOptionalField, ValidationErrorWithoutField, ValidationResult, ValidationSuccess, Validator, WithField, WithOptionalField, WithoutField };
|