@angular/forms 21.1.0-next.1 → 21.1.0-next.2
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 +453 -385
- package/fesm2022/_structure-chunk.mjs.map +1 -1
- package/fesm2022/forms.mjs +133 -133
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +9 -6
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +276 -293
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +4 -4
- package/types/_structure-chunk.d.ts +788 -708
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +1 -1
- package/types/signals.d.ts +191 -225
package/types/forms.d.ts
CHANGED
package/types/signals.d.ts
CHANGED
|
@@ -1,152 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.1.0-next.
|
|
2
|
+
* @license Angular v21.1.0-next.2
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
export { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, CustomValidationError, EmailValidationError, FIELD, Field, FieldState, FieldTree, FormOptions, ItemFieldContext, ItemType, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MaybeFieldTree, MaybeSchemaPathTree, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PatternValidationError, REQUIRED, ReadonlyArrayLike, RequiredValidationError, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SignalFormsConfig, StandardSchemaValidationError, Subfields, SubmittedStatus, ValidationResult, ValidationSuccess, Validator, WithField, WithoutField, andMetadataKey, apply, applyEach, applyWhen, applyWhenValue, createMetadataKey, customError, emailError, form, listMetadataKey, maxError, maxLengthError, maxMetadataKey, minError, minLengthError, minMetadataKey, orMetadataKey, patternError, provideSignalFormsConfig, reducedMetadataKey, requiredError, schema, standardSchemaError, submit } from './_structure-chunk.js';
|
|
7
|
+
import { InputSignal, InputSignalWithTransform, ModelSignal, OutputRef, Signal, ResourceRef } from '@angular/core';
|
|
8
|
+
import { WithOptionalField, ValidationError, DisabledReason, PathKind, SchemaPath, SchemaPathRules, LogicFn, OneOrMany, SchemaPathTree, FieldValidator, FieldContext, TreeValidationResult, TreeValidator, Debouncer } from './_structure-chunk.js';
|
|
9
|
+
export { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, CustomValidationError, EmailValidationError, FIELD, Field, FieldState, FieldTree, FormOptions, ItemFieldContext, ItemType, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MaybeFieldTree, MaybeSchemaPathTree, MetadataKey, MetadataReducer, MetadataSetterType, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PatternValidationError, REQUIRED, ReadonlyArrayLike, RequiredValidationError, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SignalFormsConfig, StandardSchemaValidationError, Subfields, SubmittedStatus, ValidationResult, ValidationSuccess, Validator, WithField, WithoutField, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, customError, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit } from './_structure-chunk.js';
|
|
11
10
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
11
|
+
import { HttpResourceRequest, HttpResourceOptions } from '@angular/common/http';
|
|
12
12
|
import '@angular/forms';
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* A function that takes the result of an async operation and the current field context, and maps it
|
|
16
|
-
* to a list of validation errors.
|
|
17
|
-
*
|
|
18
|
-
* @param result The result of the async operation.
|
|
19
|
-
* @param ctx The context for the field the validator is attached to.
|
|
20
|
-
* @return A validation error, or list of validation errors to report based on the result of the async operation.
|
|
21
|
-
* The returned errors can optionally specify a field that the error should be targeted to.
|
|
22
|
-
* A targeted error will show up as an error on its target field rather than the field being validated.
|
|
23
|
-
* If a field is not given, the error is assumed to apply to the field being validated.
|
|
24
|
-
* @template TValue The type of value stored in the field being validated.
|
|
25
|
-
* @template TResult The type of result returned by the async operation
|
|
26
|
-
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
27
|
-
*
|
|
28
|
-
* @experimental 21.0.0
|
|
29
|
-
*/
|
|
30
|
-
type MapToErrorsFn<TValue, TResult, TPathKind extends PathKind = PathKind.Root> = (result: TResult, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
|
|
31
|
-
/**
|
|
32
|
-
* Options that indicate how to create a resource for async validation for a field,
|
|
33
|
-
* and map its result to validation errors.
|
|
34
|
-
*
|
|
35
|
-
* @template TValue The type of value stored in the field being validated.
|
|
36
|
-
* @template TParams The type of parameters to the resource.
|
|
37
|
-
* @template TResult The type of result returned by the resource
|
|
38
|
-
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
39
|
-
*
|
|
40
|
-
* @category validation
|
|
41
|
-
* @experimental 21.0.0
|
|
42
|
-
*/
|
|
43
|
-
interface AsyncValidatorOptions<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root> {
|
|
44
|
-
/**
|
|
45
|
-
* A function that receives the field context and returns the params for the resource.
|
|
46
|
-
*
|
|
47
|
-
* @param ctx The field context for the field being validated.
|
|
48
|
-
* @returns The params for the resource.
|
|
49
|
-
*/
|
|
50
|
-
readonly params: (ctx: FieldContext<TValue, TPathKind>) => TParams;
|
|
51
|
-
/**
|
|
52
|
-
* A function that receives the resource params and returns a resource of the given params.
|
|
53
|
-
* The given params should be used as is to create the resource.
|
|
54
|
-
* The forms system will report the params as `undefined` when this validation doesn't need to be run.
|
|
55
|
-
*
|
|
56
|
-
* @param params The params to use for constructing the resource
|
|
57
|
-
* @returns A reference to the constructed resource.
|
|
58
|
-
*/
|
|
59
|
-
readonly factory: (params: Signal<TParams | undefined>) => ResourceRef<TResult | undefined>;
|
|
60
|
-
/**
|
|
61
|
-
* A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
|
|
62
|
-
* Receives the error and the field context, returns a list of validation errors.
|
|
63
|
-
*/
|
|
64
|
-
readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
|
|
65
|
-
/**
|
|
66
|
-
* A function that takes the resource result, and the current field context and maps it to a list
|
|
67
|
-
* of validation errors.
|
|
68
|
-
*
|
|
69
|
-
* @param result The resource result.
|
|
70
|
-
* @param ctx The context for the field the validator is attached to.
|
|
71
|
-
* @return A validation error, or list of validation errors to report based on the resource result.
|
|
72
|
-
* The returned errors can optionally specify a field that the error should be targeted to.
|
|
73
|
-
* A targeted error will show up as an error on its target field rather than the field being validated.
|
|
74
|
-
* If a field is not given, the error is assumed to apply to the field being validated.
|
|
75
|
-
*/
|
|
76
|
-
readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Options that indicate how to create an httpResource for async validation for a field,
|
|
80
|
-
* and map its result to validation errors.
|
|
81
|
-
*
|
|
82
|
-
* @template TValue The type of value stored in the field being validated.
|
|
83
|
-
* @template TResult The type of result returned by the httpResource
|
|
84
|
-
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
85
|
-
*
|
|
86
|
-
* @category validation
|
|
87
|
-
* @experimental 21.0.0
|
|
88
|
-
*/
|
|
89
|
-
interface HttpValidatorOptions<TValue, TResult, TPathKind extends PathKind = PathKind.Root> {
|
|
90
|
-
/**
|
|
91
|
-
* A function that receives the field context and returns the url or request for the httpResource.
|
|
92
|
-
* If given a URL, the underlying httpResource will perform an HTTP GET on it.
|
|
93
|
-
*
|
|
94
|
-
* @param ctx The field context for the field being validated.
|
|
95
|
-
* @returns The URL or request for creating the httpResource.
|
|
96
|
-
*/
|
|
97
|
-
readonly request: ((ctx: FieldContext<TValue, TPathKind>) => string | undefined) | ((ctx: FieldContext<TValue, TPathKind>) => HttpResourceRequest | undefined);
|
|
98
|
-
/**
|
|
99
|
-
* A function that takes the httpResource result, and the current field context and maps it to a
|
|
100
|
-
* list of validation errors.
|
|
101
|
-
*
|
|
102
|
-
* @param result The httpResource result.
|
|
103
|
-
* @param ctx The context for the field the validator is attached to.
|
|
104
|
-
* @return A validation error, or list of validation errors to report based on the httpResource result.
|
|
105
|
-
* The returned errors can optionally specify a field that the error should be targeted to.
|
|
106
|
-
* A targeted error will show up as an error on its target field rather than the field being validated.
|
|
107
|
-
* If a field is not given, the error is assumed to apply to the field being validated.
|
|
108
|
-
*/
|
|
109
|
-
readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
|
|
110
|
-
/**
|
|
111
|
-
* A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
|
|
112
|
-
* Receives the error and the field context, returns a list of validation errors.
|
|
113
|
-
*/
|
|
114
|
-
readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
|
|
115
|
-
/**
|
|
116
|
-
* The options to use when creating the httpResource.
|
|
117
|
-
*/
|
|
118
|
-
readonly options?: HttpResourceOptions<TResult, unknown>;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Adds async validation to the field corresponding to the given path based on a resource.
|
|
122
|
-
* Async validation for a field only runs once all synchronous validation is passing.
|
|
123
|
-
*
|
|
124
|
-
* @param path A path indicating the field to bind the async validation logic to.
|
|
125
|
-
* @param opts The async validation options.
|
|
126
|
-
* @template TValue The type of value stored in the field being validated.
|
|
127
|
-
* @template TParams The type of parameters to the resource.
|
|
128
|
-
* @template TResult The type of result returned by the resource
|
|
129
|
-
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
130
|
-
*
|
|
131
|
-
* @category validation
|
|
132
|
-
* @experimental 21.0.0
|
|
133
|
-
*/
|
|
134
|
-
declare function validateAsync<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: AsyncValidatorOptions<TValue, TParams, TResult, TPathKind>): void;
|
|
135
|
-
/**
|
|
136
|
-
* Adds async validation to the field corresponding to the given path based on an httpResource.
|
|
137
|
-
* Async validation for a field only runs once all synchronous validation is passing.
|
|
138
|
-
*
|
|
139
|
-
* @param path A path indicating the field to bind the async validation logic to.
|
|
140
|
-
* @param opts The http validation options.
|
|
141
|
-
* @template TValue The type of value stored in the field being validated.
|
|
142
|
-
* @template TResult The type of result returned by the httpResource
|
|
143
|
-
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
144
|
-
*
|
|
145
|
-
* @category validation
|
|
146
|
-
* @experimental 21.0.0
|
|
147
|
-
*/
|
|
148
|
-
declare function validateHttp<TValue, TResult = unknown, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: HttpValidatorOptions<TValue, TResult, TPathKind>): void;
|
|
149
|
-
|
|
150
14
|
/**
|
|
151
15
|
* The base set of properties shared by all form control contracts.
|
|
152
16
|
*
|
|
@@ -286,20 +150,6 @@ interface FormCheckboxControl extends FormUiControl {
|
|
|
286
150
|
readonly value?: undefined;
|
|
287
151
|
}
|
|
288
152
|
|
|
289
|
-
/**
|
|
290
|
-
* Configures the frequency at which a form field is updated by UI events.
|
|
291
|
-
*
|
|
292
|
-
* When this rule is applied, updates from the UI to the form model will be delayed until either
|
|
293
|
-
* the field is touched, or the most recently debounced update resolves.
|
|
294
|
-
*
|
|
295
|
-
* @param path The target path to debounce.
|
|
296
|
-
* @param durationOrDebouncer Either a debounce duration in milliseconds, or a custom
|
|
297
|
-
* {@link Debouncer} function.
|
|
298
|
-
*
|
|
299
|
-
* @experimental 21.0.0
|
|
300
|
-
*/
|
|
301
|
-
declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, durationOrDebouncer: number | Debouncer<TValue, TPathKind>): void;
|
|
302
|
-
|
|
303
153
|
/**
|
|
304
154
|
* Adds logic to a field to conditionally disable it. A disabled field does not contribute to the
|
|
305
155
|
* validation, touched/dirty, or other state of its parent field.
|
|
@@ -314,19 +164,7 @@ declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(pa
|
|
|
314
164
|
* @experimental 21.0.0
|
|
315
165
|
*/
|
|
316
166
|
declare function disabled<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: string | NoInfer<LogicFn<TValue, boolean | string, TPathKind>>): void;
|
|
317
|
-
|
|
318
|
-
* Adds logic to a field to conditionally make it readonly. A readonly field does not contribute to
|
|
319
|
-
* the validation, touched/dirty, or other state of its parent field.
|
|
320
|
-
*
|
|
321
|
-
* @param path The target path to make readonly.
|
|
322
|
-
* @param logic A reactive function that returns `true` when the field is readonly.
|
|
323
|
-
* @template TValue The type of value stored in the field the logic is bound to.
|
|
324
|
-
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
325
|
-
*
|
|
326
|
-
* @category logic
|
|
327
|
-
* @experimental 21.0.0
|
|
328
|
-
*/
|
|
329
|
-
declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: NoInfer<LogicFn<TValue, boolean, TPathKind>>): void;
|
|
167
|
+
|
|
330
168
|
/**
|
|
331
169
|
* Adds logic to a field to conditionally hide it. A hidden field does not contribute to the
|
|
332
170
|
* validation, touched/dirty, or other state of its parent field.
|
|
@@ -348,70 +186,20 @@ declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(pa
|
|
|
348
186
|
* @experimental 21.0.0
|
|
349
187
|
*/
|
|
350
188
|
declare function hidden<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<LogicFn<TValue, boolean, TPathKind>>): void;
|
|
189
|
+
|
|
351
190
|
/**
|
|
352
|
-
* Adds logic to a field to
|
|
353
|
-
*
|
|
354
|
-
* @param path The target path to add the validation logic to.
|
|
355
|
-
* @param logic A `Validator` that returns the current validation errors.
|
|
356
|
-
* @template TValue The type of value stored in the field the logic is bound to.
|
|
357
|
-
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
358
|
-
*
|
|
359
|
-
* @category logic
|
|
360
|
-
* @experimental 21.0.0
|
|
361
|
-
*/
|
|
362
|
-
declare function validate<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<FieldValidator<TValue, TPathKind>>): void;
|
|
363
|
-
/**
|
|
364
|
-
* Adds logic to a field to determine if the field or any of its child fields has validation errors.
|
|
365
|
-
*
|
|
366
|
-
* @param path The target path to add the validation logic to.
|
|
367
|
-
* @param logic A `TreeValidator` that returns the current validation errors.
|
|
368
|
-
* Errors returned by the validator may specify a target field to indicate an error on a child field.
|
|
369
|
-
* @template TValue The type of value stored in the field the logic is bound to.
|
|
370
|
-
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
371
|
-
*
|
|
372
|
-
* @category logic
|
|
373
|
-
* @experimental 21.0.0
|
|
374
|
-
*/
|
|
375
|
-
declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<TreeValidator<TValue, TPathKind>>): void;
|
|
376
|
-
/**
|
|
377
|
-
* Adds a value to an {@link AggregateMetadataKey} of a field.
|
|
191
|
+
* Adds logic to a field to conditionally make it readonly. A readonly field does not contribute to
|
|
192
|
+
* the validation, touched/dirty, or other state of its parent field.
|
|
378
193
|
*
|
|
379
|
-
* @param path The target path to
|
|
380
|
-
* @param
|
|
381
|
-
* @param logic A function that receives the `FieldContext` and returns a value to add to the aggregate metadata.
|
|
194
|
+
* @param path The target path to make readonly.
|
|
195
|
+
* @param logic A reactive function that returns `true` when the field is readonly.
|
|
382
196
|
* @template TValue The type of value stored in the field the logic is bound to.
|
|
383
|
-
* @template TMetadataItem The type of value the metadata aggregates over.
|
|
384
197
|
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
385
198
|
*
|
|
386
199
|
* @category logic
|
|
387
200
|
* @experimental 21.0.0
|
|
388
201
|
*/
|
|
389
|
-
declare function
|
|
390
|
-
/**
|
|
391
|
-
* Creates a new {@link MetadataKey} and defines the value of the new metadata key for the given field.
|
|
392
|
-
*
|
|
393
|
-
* @param path The path to define the metadata for.
|
|
394
|
-
* @param factory A factory function that creates the value for the metadata.
|
|
395
|
-
* This function is **not** reactive. It is run once when the field is created.
|
|
396
|
-
* @returns The newly created metadata key
|
|
397
|
-
*
|
|
398
|
-
* @category logic
|
|
399
|
-
* @experimental 21.0.0
|
|
400
|
-
*/
|
|
401
|
-
declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, factory: (ctx: FieldContext<TValue, TPathKind>) => TData): MetadataKey<TData>;
|
|
402
|
-
/**
|
|
403
|
-
* Defines the value of a {@link MetadataKey} for a given field.
|
|
404
|
-
*
|
|
405
|
-
* @param path The path to define the metadata for.
|
|
406
|
-
* @param key The metadata key to define.
|
|
407
|
-
* @param factory A factory function that creates the value for the metadata.
|
|
408
|
-
* This function is **not** reactive. It is run once when the field is created.
|
|
409
|
-
* @returns The given metadata key
|
|
410
|
-
*
|
|
411
|
-
* @category logic
|
|
412
|
-
* @experimental 21.0.0
|
|
413
|
-
*/
|
|
414
|
-
declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, key: MetadataKey<TData>, factory: (ctx: FieldContext<TValue, TPathKind>) => TData): MetadataKey<TData>;
|
|
202
|
+
declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: NoInfer<LogicFn<TValue, boolean, TPathKind>>): void;
|
|
415
203
|
|
|
416
204
|
/** Represents a value that has a length or size, such as an array or string, or set. */
|
|
417
205
|
type ValueWithLengthOrSize = {
|
|
@@ -594,5 +382,183 @@ type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
|
|
|
594
382
|
*/
|
|
595
383
|
declare function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProperties<TSchema>>(path: SchemaPath<TModel> & SchemaPathTree<TModel>, schema: StandardSchemaV1<TSchema>): void;
|
|
596
384
|
|
|
597
|
-
|
|
385
|
+
/**
|
|
386
|
+
* Adds logic to a field to determine if the field has validation errors.
|
|
387
|
+
*
|
|
388
|
+
* @param path The target path to add the validation logic to.
|
|
389
|
+
* @param logic A `Validator` that returns the current validation errors.
|
|
390
|
+
* @template TValue The type of value stored in the field the logic is bound to.
|
|
391
|
+
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
392
|
+
*
|
|
393
|
+
* @category logic
|
|
394
|
+
* @experimental 21.0.0
|
|
395
|
+
*/
|
|
396
|
+
declare function validate<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<FieldValidator<TValue, TPathKind>>): void;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* A function that takes the result of an async operation and the current field context, and maps it
|
|
400
|
+
* to a list of validation errors.
|
|
401
|
+
*
|
|
402
|
+
* @param result The result of the async operation.
|
|
403
|
+
* @param ctx The context for the field the validator is attached to.
|
|
404
|
+
* @return A validation error, or list of validation errors to report based on the result of the async operation.
|
|
405
|
+
* The returned errors can optionally specify a field that the error should be targeted to.
|
|
406
|
+
* A targeted error will show up as an error on its target field rather than the field being validated.
|
|
407
|
+
* If a field is not given, the error is assumed to apply to the field being validated.
|
|
408
|
+
* @template TValue The type of value stored in the field being validated.
|
|
409
|
+
* @template TResult The type of result returned by the async operation
|
|
410
|
+
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
411
|
+
*
|
|
412
|
+
* @experimental 21.0.0
|
|
413
|
+
*/
|
|
414
|
+
type MapToErrorsFn<TValue, TResult, TPathKind extends PathKind = PathKind.Root> = (result: TResult, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
|
|
415
|
+
/**
|
|
416
|
+
* Options that indicate how to create a resource for async validation for a field,
|
|
417
|
+
* and map its result to validation errors.
|
|
418
|
+
*
|
|
419
|
+
* @template TValue The type of value stored in the field being validated.
|
|
420
|
+
* @template TParams The type of parameters to the resource.
|
|
421
|
+
* @template TResult The type of result returned by the resource
|
|
422
|
+
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
423
|
+
*
|
|
424
|
+
* @category validation
|
|
425
|
+
* @experimental 21.0.0
|
|
426
|
+
*/
|
|
427
|
+
interface AsyncValidatorOptions<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root> {
|
|
428
|
+
/**
|
|
429
|
+
* A function that receives the field context and returns the params for the resource.
|
|
430
|
+
*
|
|
431
|
+
* @param ctx The field context for the field being validated.
|
|
432
|
+
* @returns The params for the resource.
|
|
433
|
+
*/
|
|
434
|
+
readonly params: (ctx: FieldContext<TValue, TPathKind>) => TParams;
|
|
435
|
+
/**
|
|
436
|
+
* A function that receives the resource params and returns a resource of the given params.
|
|
437
|
+
* The given params should be used as is to create the resource.
|
|
438
|
+
* The forms system will report the params as `undefined` when this validation doesn't need to be run.
|
|
439
|
+
*
|
|
440
|
+
* @param params The params to use for constructing the resource
|
|
441
|
+
* @returns A reference to the constructed resource.
|
|
442
|
+
*/
|
|
443
|
+
readonly factory: (params: Signal<TParams | undefined>) => ResourceRef<TResult | undefined>;
|
|
444
|
+
/**
|
|
445
|
+
* A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
|
|
446
|
+
* Receives the error and the field context, returns a list of validation errors.
|
|
447
|
+
*/
|
|
448
|
+
readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
|
|
449
|
+
/**
|
|
450
|
+
* A function that takes the resource result, and the current field context and maps it to a list
|
|
451
|
+
* of validation errors.
|
|
452
|
+
*
|
|
453
|
+
* @param result The resource result.
|
|
454
|
+
* @param ctx The context for the field the validator is attached to.
|
|
455
|
+
* @return A validation error, or list of validation errors to report based on the resource result.
|
|
456
|
+
* The returned errors can optionally specify a field that the error should be targeted to.
|
|
457
|
+
* A targeted error will show up as an error on its target field rather than the field being validated.
|
|
458
|
+
* If a field is not given, the error is assumed to apply to the field being validated.
|
|
459
|
+
*/
|
|
460
|
+
readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Adds async validation to the field corresponding to the given path based on a resource.
|
|
464
|
+
* Async validation for a field only runs once all synchronous validation is passing.
|
|
465
|
+
*
|
|
466
|
+
* @param path A path indicating the field to bind the async validation logic to.
|
|
467
|
+
* @param opts The async validation options.
|
|
468
|
+
* @template TValue The type of value stored in the field being validated.
|
|
469
|
+
* @template TParams The type of parameters to the resource.
|
|
470
|
+
* @template TResult The type of result returned by the resource
|
|
471
|
+
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
472
|
+
*
|
|
473
|
+
* @category validation
|
|
474
|
+
* @experimental 21.0.0
|
|
475
|
+
*/
|
|
476
|
+
declare function validateAsync<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: AsyncValidatorOptions<TValue, TParams, TResult, TPathKind>): void;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Options that indicate how to create an httpResource for async validation for a field,
|
|
480
|
+
* and map its result to validation errors.
|
|
481
|
+
*
|
|
482
|
+
* @template TValue The type of value stored in the field being validated.
|
|
483
|
+
* @template TResult The type of result returned by the httpResource
|
|
484
|
+
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
485
|
+
*
|
|
486
|
+
* @category validation
|
|
487
|
+
* @experimental 21.0.0
|
|
488
|
+
*/
|
|
489
|
+
interface HttpValidatorOptions<TValue, TResult, TPathKind extends PathKind = PathKind.Root> {
|
|
490
|
+
/**
|
|
491
|
+
* A function that receives the field context and returns the url or request for the httpResource.
|
|
492
|
+
* If given a URL, the underlying httpResource will perform an HTTP GET on it.
|
|
493
|
+
*
|
|
494
|
+
* @param ctx The field context for the field being validated.
|
|
495
|
+
* @returns The URL or request for creating the httpResource.
|
|
496
|
+
*/
|
|
497
|
+
readonly request: ((ctx: FieldContext<TValue, TPathKind>) => string | undefined) | ((ctx: FieldContext<TValue, TPathKind>) => HttpResourceRequest | undefined);
|
|
498
|
+
/**
|
|
499
|
+
* A function that takes the httpResource result, and the current field context and maps it to a
|
|
500
|
+
* list of validation errors.
|
|
501
|
+
*
|
|
502
|
+
* @param result The httpResource result.
|
|
503
|
+
* @param ctx The context for the field the validator is attached to.
|
|
504
|
+
* @return A validation error, or list of validation errors to report based on the httpResource result.
|
|
505
|
+
* The returned errors can optionally specify a field that the error should be targeted to.
|
|
506
|
+
* A targeted error will show up as an error on its target field rather than the field being validated.
|
|
507
|
+
* If a field is not given, the error is assumed to apply to the field being validated.
|
|
508
|
+
*/
|
|
509
|
+
readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
|
|
510
|
+
/**
|
|
511
|
+
* A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
|
|
512
|
+
* Receives the error and the field context, returns a list of validation errors.
|
|
513
|
+
*/
|
|
514
|
+
readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
|
|
515
|
+
/**
|
|
516
|
+
* The options to use when creating the httpResource.
|
|
517
|
+
*/
|
|
518
|
+
readonly options?: HttpResourceOptions<TResult, unknown>;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Adds async validation to the field corresponding to the given path based on an httpResource.
|
|
522
|
+
* Async validation for a field only runs once all synchronous validation is passing.
|
|
523
|
+
*
|
|
524
|
+
* @param path A path indicating the field to bind the async validation logic to.
|
|
525
|
+
* @param opts The http validation options.
|
|
526
|
+
* @template TValue The type of value stored in the field being validated.
|
|
527
|
+
* @template TResult The type of result returned by the httpResource
|
|
528
|
+
* @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
|
|
529
|
+
*
|
|
530
|
+
* @category validation
|
|
531
|
+
* @experimental 21.0.0
|
|
532
|
+
*/
|
|
533
|
+
declare function validateHttp<TValue, TResult = unknown, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: HttpValidatorOptions<TValue, TResult, TPathKind>): void;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Adds logic to a field to determine if the field or any of its child fields has validation errors.
|
|
537
|
+
*
|
|
538
|
+
* @param path The target path to add the validation logic to.
|
|
539
|
+
* @param logic A `TreeValidator` that returns the current validation errors.
|
|
540
|
+
* Errors returned by the validator may specify a target field to indicate an error on a child field.
|
|
541
|
+
* @template TValue The type of value stored in the field the logic is bound to.
|
|
542
|
+
* @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
|
|
543
|
+
*
|
|
544
|
+
* @category logic
|
|
545
|
+
* @experimental 21.0.0
|
|
546
|
+
*/
|
|
547
|
+
declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<TreeValidator<TValue, TPathKind>>): void;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Configures the frequency at which a form field is updated by UI events.
|
|
551
|
+
*
|
|
552
|
+
* When this rule is applied, updates from the UI to the form model will be delayed until either
|
|
553
|
+
* the field is touched, or the most recently debounced update resolves.
|
|
554
|
+
*
|
|
555
|
+
* @param path The target path to debounce.
|
|
556
|
+
* @param durationOrDebouncer Either a debounce duration in milliseconds, or a custom
|
|
557
|
+
* {@link Debouncer} function.
|
|
558
|
+
*
|
|
559
|
+
* @experimental 21.0.0
|
|
560
|
+
*/
|
|
561
|
+
declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, durationOrDebouncer: number | Debouncer<TValue, TPathKind>): void;
|
|
562
|
+
|
|
563
|
+
export { Debouncer, DisabledReason, FieldContext, FieldValidator, LogicFn, OneOrMany, PathKind, SchemaPath, SchemaPathRules, SchemaPathTree, TreeValidationResult, TreeValidator, ValidationError, WithOptionalField, debounce, disabled, email, hidden, max, maxLength, min, minLength, pattern, readonly, required, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
|
|
598
564
|
export type { AsyncValidatorOptions, FormCheckboxControl, FormUiControl, FormValueControl, HttpValidatorOptions, IgnoreUnknownProperties, MapToErrorsFn, RemoveStringIndexUnknownKey };
|