@angular/forms 21.2.0-next.0 → 21.2.0-next.1
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 +37 -5
- package/fesm2022/_structure-chunk.mjs.map +1 -1
- package/fesm2022/forms.mjs +128 -128
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +4 -1
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +26 -11
- 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 +168 -143
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +1 -1
- package/types/signals.d.ts +15 -9
|
@@ -1,112 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.2.0-next.
|
|
2
|
+
* @license Angular v21.2.0-next.1
|
|
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 { ɵFormFieldBindingOptions as _FormFieldBindingOptions, InjectionToken, Injector, ɵCONTROL as _CONTROL, ɵɵcontrolCreate as __controlCreate, ɵcontrolUpdate as _controlUpdate,
|
|
8
|
+
import { Signal, ɵFieldState as _FieldState, ɵFormFieldBindingOptions as _FormFieldBindingOptions, InjectionToken, Injector, ɵCONTROL as _CONTROL, ɵɵcontrolCreate as __controlCreate, ɵcontrolUpdate as _controlUpdate, Provider, WritableSignal, DestroyableInjector } from '@angular/core';
|
|
9
9
|
import * as _angular_forms from '@angular/forms';
|
|
10
|
-
import {
|
|
10
|
+
import { AbstractControl, NgControl, ValidationErrors, FormControlStatus, ControlValueAccessor, ValidatorFn } from '@angular/forms';
|
|
11
11
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* Properties of both NgControl & AbstractControl that are supported by the InteropNgControl.
|
|
15
|
-
*/
|
|
16
|
-
type InteropSharedKeys = 'value' | 'valid' | 'invalid' | 'touched' | 'untouched' | 'disabled' | 'enabled' | 'errors' | 'pristine' | 'dirty' | 'status';
|
|
17
|
-
/**
|
|
18
|
-
* A fake version of `NgControl` provided by the `Field` directive. This allows interoperability
|
|
19
|
-
* with a wider range of components designed to work with reactive forms, in particular ones that
|
|
20
|
-
* inject the `NgControl`. The interop control does not implement *all* properties and methods of
|
|
21
|
-
* the real `NgControl`, but does implement some of the most commonly used ones that have a clear
|
|
22
|
-
* equivalent in signal forms.
|
|
23
|
-
*/
|
|
24
|
-
declare class InteropNgControl implements Pick<NgControl, InteropSharedKeys | 'control' | 'valueAccessor'>, Pick<AbstractControl<unknown>, InteropSharedKeys | 'hasValidator'> {
|
|
25
|
-
protected field: () => FieldState<unknown>;
|
|
26
|
-
constructor(field: () => FieldState<unknown>);
|
|
27
|
-
readonly control: AbstractControl<any, any>;
|
|
28
|
-
get value(): any;
|
|
29
|
-
get valid(): boolean;
|
|
30
|
-
get invalid(): boolean;
|
|
31
|
-
get pending(): boolean | null;
|
|
32
|
-
get disabled(): boolean;
|
|
33
|
-
get enabled(): boolean;
|
|
34
|
-
get errors(): ValidationErrors | null;
|
|
35
|
-
get pristine(): boolean;
|
|
36
|
-
get dirty(): boolean;
|
|
37
|
-
get touched(): boolean;
|
|
38
|
-
get untouched(): boolean;
|
|
39
|
-
get status(): FormControlStatus;
|
|
40
|
-
valueAccessor: ControlValueAccessor | null;
|
|
41
|
-
hasValidator(validator: ValidatorFn): boolean;
|
|
42
|
-
updateValueAndValidity(): void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface FormFieldBindingOptions extends _FormFieldBindingOptions {
|
|
46
|
-
/**
|
|
47
|
-
* Focuses the binding.
|
|
48
|
-
*
|
|
49
|
-
* If not specified, Signal Forms will attempt to focus the host element of the `FormField` when
|
|
50
|
-
* asked to focus this binding.
|
|
51
|
-
*/
|
|
52
|
-
focus?(options?: FocusOptions): void;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Lightweight DI token provided by the {@link FormField} directive.
|
|
56
|
-
*
|
|
57
|
-
* @category control
|
|
58
|
-
* @experimental 21.0.0
|
|
59
|
-
*/
|
|
60
|
-
declare const FORM_FIELD: InjectionToken<FormField<unknown>>;
|
|
61
|
-
/**
|
|
62
|
-
* Binds a form `FieldTree` to a UI control that edits it. A UI control can be one of several things:
|
|
63
|
-
* 1. A native HTML input or textarea
|
|
64
|
-
* 2. A signal forms custom control that implements `FormValueControl` or `FormCheckboxControl`
|
|
65
|
-
* 3. A component that provides a `ControlValueAccessor`. This should only be used for backwards
|
|
66
|
-
* compatibility with reactive forms. Prefer options (1) and (2).
|
|
67
|
-
*
|
|
68
|
-
* This directive has several responsibilities:
|
|
69
|
-
* 1. Two-way binds the field state's value with the UI control's value
|
|
70
|
-
* 2. Binds additional forms related state on the field state to the UI control (disabled, required, etc.)
|
|
71
|
-
* 3. Relays relevant events on the control to the field state (e.g. marks touched on blur)
|
|
72
|
-
* 4. Provides a fake `NgControl` that implements a subset of the features available on the
|
|
73
|
-
* reactive forms `NgControl`. This is provided to improve interoperability with controls
|
|
74
|
-
* designed to work with reactive forms. It should not be used by controls written for signal
|
|
75
|
-
* forms.
|
|
76
|
-
*
|
|
77
|
-
* @category control
|
|
78
|
-
* @experimental 21.0.0
|
|
79
|
-
*/
|
|
80
|
-
declare class FormField<T> {
|
|
81
|
-
readonly element: HTMLElement;
|
|
82
|
-
readonly injector: Injector;
|
|
83
|
-
readonly formField: i0.InputSignal<FieldTree<T>>;
|
|
84
|
-
readonly state: i0.Signal<[T] extends [_angular_forms.AbstractControl<any, any, any>] ? CompatFieldState<T, string | number> : FieldState<T, string | number>>;
|
|
85
|
-
private readonly bindingOptions;
|
|
86
|
-
readonly [_CONTROL]: {
|
|
87
|
-
readonly create: typeof __controlCreate;
|
|
88
|
-
readonly update: typeof _controlUpdate;
|
|
89
|
-
};
|
|
90
|
-
private config;
|
|
91
|
-
/** Any `ControlValueAccessor` instances provided on the host element. */
|
|
92
|
-
private readonly controlValueAccessors;
|
|
93
|
-
/** A lazily instantiated fake `NgControl`. */
|
|
94
|
-
private interopNgControl;
|
|
95
|
-
/** Lazily instantiates a fake `NgControl` for this form field. */
|
|
96
|
-
protected getOrCreateNgControl(): InteropNgControl;
|
|
97
|
-
/**
|
|
98
|
-
* Registers this `FormField` as a binding on its associated `FieldState`.
|
|
99
|
-
*
|
|
100
|
-
* This method should be called at most once for a given `FormField`. A `FormField` placed on a
|
|
101
|
-
* custom control (`FormUiControl`) automatically registers that custom control as a binding.
|
|
102
|
-
*/
|
|
103
|
-
registerAsBinding(bindingOptions?: FormFieldBindingOptions): void;
|
|
104
|
-
/** Focuses this UI control. */
|
|
105
|
-
focus(options?: FocusOptions): void;
|
|
106
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<FormField<any>, never>;
|
|
107
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<FormField<any>, "[formField]", never, { "formField": { "alias": "formField"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
13
|
/**
|
|
111
14
|
* Sets a value for the {@link MetadataKey} for this field.
|
|
112
15
|
*
|
|
@@ -348,7 +251,7 @@ type ValidationSuccess = null | undefined | void;
|
|
|
348
251
|
* @category types
|
|
349
252
|
* @experimental 21.0.0
|
|
350
253
|
*/
|
|
351
|
-
type TreeValidationResult<E extends ValidationError.
|
|
254
|
+
type TreeValidationResult<E extends ValidationError.WithOptionalFieldTree = ValidationError.WithOptionalFieldTree> = ValidationSuccess | OneOrMany<E>;
|
|
352
255
|
/**
|
|
353
256
|
* A validation result where all errors explicitly define their target field.
|
|
354
257
|
*
|
|
@@ -449,11 +352,11 @@ interface FieldState<TValue, TKey extends string | number = string | number> ext
|
|
|
449
352
|
*/
|
|
450
353
|
readonly hidden: Signal<boolean>;
|
|
451
354
|
readonly disabledReasons: Signal<readonly DisabledReason[]>;
|
|
452
|
-
readonly errors: Signal<ValidationError.
|
|
355
|
+
readonly errors: Signal<ValidationError.WithFieldTree[]>;
|
|
453
356
|
/**
|
|
454
357
|
* A signal containing the {@link errors} of the field and its descendants.
|
|
455
358
|
*/
|
|
456
|
-
readonly errorSummary: Signal<ValidationError.
|
|
359
|
+
readonly errorSummary: Signal<ValidationError.WithFieldTree[]>;
|
|
457
360
|
/**
|
|
458
361
|
* A signal indicating whether the field's value is currently valid.
|
|
459
362
|
*
|
|
@@ -691,7 +594,7 @@ type LogicFn<TValue, TReturn, TPathKind extends PathKind = PathKind.Root> = (ctx
|
|
|
691
594
|
* @category validation
|
|
692
595
|
* @experimental 21.0.0
|
|
693
596
|
*/
|
|
694
|
-
type FieldValidator<TValue, TPathKind extends PathKind = PathKind.Root> = LogicFn<TValue, ValidationResult<ValidationError.
|
|
597
|
+
type FieldValidator<TValue, TPathKind extends PathKind = PathKind.Root> = LogicFn<TValue, ValidationResult<ValidationError.WithoutFieldTree>, TPathKind>;
|
|
695
598
|
/**
|
|
696
599
|
* A function that takes the `FieldContext` for the field being validated and returns a
|
|
697
600
|
* `TreeValidationResult` indicating errors for the field and its sub-fields.
|
|
@@ -783,6 +686,106 @@ type ItemType<T extends Object> = T extends ReadonlyArray<any> ? T[number] : T[k
|
|
|
783
686
|
*/
|
|
784
687
|
type Debouncer<TValue, TPathKind extends PathKind = PathKind.Root> = (context: FieldContext<TValue, TPathKind>, abortSignal: AbortSignal) => Promise<void> | void;
|
|
785
688
|
|
|
689
|
+
/**
|
|
690
|
+
* Properties of both NgControl & AbstractControl that are supported by the InteropNgControl.
|
|
691
|
+
*/
|
|
692
|
+
type InteropSharedKeys = 'value' | 'valid' | 'invalid' | 'touched' | 'untouched' | 'disabled' | 'enabled' | 'errors' | 'pristine' | 'dirty' | 'status';
|
|
693
|
+
/**
|
|
694
|
+
* A fake version of `NgControl` provided by the `Field` directive. This allows interoperability
|
|
695
|
+
* with a wider range of components designed to work with reactive forms, in particular ones that
|
|
696
|
+
* inject the `NgControl`. The interop control does not implement *all* properties and methods of
|
|
697
|
+
* the real `NgControl`, but does implement some of the most commonly used ones that have a clear
|
|
698
|
+
* equivalent in signal forms.
|
|
699
|
+
*/
|
|
700
|
+
declare class InteropNgControl implements Pick<NgControl, InteropSharedKeys | 'control' | 'valueAccessor'>, Pick<AbstractControl<unknown>, InteropSharedKeys | 'hasValidator'> {
|
|
701
|
+
protected field: () => FieldState<unknown>;
|
|
702
|
+
constructor(field: () => FieldState<unknown>);
|
|
703
|
+
readonly control: AbstractControl<any, any>;
|
|
704
|
+
get value(): any;
|
|
705
|
+
get valid(): boolean;
|
|
706
|
+
get invalid(): boolean;
|
|
707
|
+
get pending(): boolean | null;
|
|
708
|
+
get disabled(): boolean;
|
|
709
|
+
get enabled(): boolean;
|
|
710
|
+
get errors(): ValidationErrors | null;
|
|
711
|
+
get pristine(): boolean;
|
|
712
|
+
get dirty(): boolean;
|
|
713
|
+
get touched(): boolean;
|
|
714
|
+
get untouched(): boolean;
|
|
715
|
+
get status(): FormControlStatus;
|
|
716
|
+
valueAccessor: ControlValueAccessor | null;
|
|
717
|
+
hasValidator(validator: ValidatorFn): boolean;
|
|
718
|
+
updateValueAndValidity(): void;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
interface FormFieldBindingOptions<TValue> extends _FormFieldBindingOptions {
|
|
722
|
+
/**
|
|
723
|
+
* Focuses the binding.
|
|
724
|
+
*
|
|
725
|
+
* If not specified, Signal Forms will attempt to focus the host element of the `FormField` when
|
|
726
|
+
* asked to focus this binding.
|
|
727
|
+
*/
|
|
728
|
+
focus?(options?: FocusOptions): void;
|
|
729
|
+
readonly parseErrors?: Signal<ValidationError.WithoutFieldTree[]>;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Lightweight DI token provided by the {@link FormField} directive.
|
|
733
|
+
*
|
|
734
|
+
* @category control
|
|
735
|
+
* @experimental 21.0.0
|
|
736
|
+
*/
|
|
737
|
+
declare const FORM_FIELD: InjectionToken<FormField<unknown>>;
|
|
738
|
+
/**
|
|
739
|
+
* Binds a form `FieldTree` to a UI control that edits it. A UI control can be one of several things:
|
|
740
|
+
* 1. A native HTML input or textarea
|
|
741
|
+
* 2. A signal forms custom control that implements `FormValueControl` or `FormCheckboxControl`
|
|
742
|
+
* 3. A component that provides a `ControlValueAccessor`. This should only be used for backwards
|
|
743
|
+
* compatibility with reactive forms. Prefer options (1) and (2).
|
|
744
|
+
*
|
|
745
|
+
* This directive has several responsibilities:
|
|
746
|
+
* 1. Two-way binds the field state's value with the UI control's value
|
|
747
|
+
* 2. Binds additional forms related state on the field state to the UI control (disabled, required, etc.)
|
|
748
|
+
* 3. Relays relevant events on the control to the field state (e.g. marks touched on blur)
|
|
749
|
+
* 4. Provides a fake `NgControl` that implements a subset of the features available on the
|
|
750
|
+
* reactive forms `NgControl`. This is provided to improve interoperability with controls
|
|
751
|
+
* designed to work with reactive forms. It should not be used by controls written for signal
|
|
752
|
+
* forms.
|
|
753
|
+
*
|
|
754
|
+
* @category control
|
|
755
|
+
* @experimental 21.0.0
|
|
756
|
+
*/
|
|
757
|
+
declare class FormField<T> {
|
|
758
|
+
readonly element: HTMLElement;
|
|
759
|
+
readonly injector: Injector;
|
|
760
|
+
readonly fieldTree: i0.InputSignal<FieldTree<T>>;
|
|
761
|
+
readonly state: Signal<[T] extends [_angular_forms.AbstractControl<any, any, any>] ? CompatFieldState<T, string | number> : FieldState<T, string | number>>;
|
|
762
|
+
private readonly bindingOptions;
|
|
763
|
+
/** Errors associated with this form field. */
|
|
764
|
+
readonly errors: Signal<ValidationError.WithFieldTree[]>;
|
|
765
|
+
readonly [_CONTROL]: {
|
|
766
|
+
readonly create: typeof __controlCreate;
|
|
767
|
+
readonly update: typeof _controlUpdate;
|
|
768
|
+
};
|
|
769
|
+
private config;
|
|
770
|
+
/** Any `ControlValueAccessor` instances provided on the host element. */
|
|
771
|
+
private readonly controlValueAccessors;
|
|
772
|
+
/** A lazily instantiated fake `NgControl`. */
|
|
773
|
+
private interopNgControl;
|
|
774
|
+
/** Lazily instantiates a fake `NgControl` for this form field. */
|
|
775
|
+
protected getOrCreateNgControl(): InteropNgControl;
|
|
776
|
+
/**
|
|
777
|
+
* Registers this `FormField` as a binding on its associated `FieldState`.
|
|
778
|
+
*
|
|
779
|
+
* This method should be called at most once for a given `FormField`. A `FormField` placed on a
|
|
780
|
+
* custom control (`FormUiControl`) automatically registers that custom control as a binding.
|
|
781
|
+
*/
|
|
782
|
+
registerAsBinding(bindingOptions?: FormFieldBindingOptions<T>): void;
|
|
783
|
+
/** Focuses this UI control. */
|
|
784
|
+
focus(options?: FocusOptions): void;
|
|
785
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FormField<any>, never>;
|
|
786
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<FormField<any>, "[formField]", ["formField"], { "fieldTree": { "alias": "formField"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
787
|
+
}
|
|
788
|
+
|
|
786
789
|
/**
|
|
787
790
|
* Options used to create a `ValidationError`.
|
|
788
791
|
*/
|
|
@@ -796,34 +799,40 @@ interface ValidationErrorOptions {
|
|
|
796
799
|
*
|
|
797
800
|
* @experimental 21.0.0
|
|
798
801
|
*/
|
|
799
|
-
type
|
|
802
|
+
type WithFieldTree<T> = T & {
|
|
800
803
|
fieldTree: FieldTree<unknown>;
|
|
801
804
|
};
|
|
805
|
+
/** @deprecated Use `WithFieldTree` instead */
|
|
806
|
+
type WithField<T> = WithFieldTree<T>;
|
|
802
807
|
/**
|
|
803
808
|
* A type that allows the given type `T` to optionally have a `field` property.
|
|
804
809
|
* @template T The type to optionally add a `field` to.
|
|
805
810
|
*
|
|
806
811
|
* @experimental 21.0.0
|
|
807
812
|
*/
|
|
808
|
-
type
|
|
813
|
+
type WithOptionalFieldTree<T> = Omit<T, 'fieldTree'> & {
|
|
809
814
|
fieldTree?: FieldTree<unknown>;
|
|
810
815
|
};
|
|
816
|
+
/** @deprecated Use `WithOptionalFieldTree` instead */
|
|
817
|
+
type WithOptionalField<T> = WithOptionalFieldTree<T>;
|
|
811
818
|
/**
|
|
812
819
|
* A type that ensures the given type `T` does not have a `field` property.
|
|
813
820
|
* @template T The type to remove the `field` from.
|
|
814
821
|
*
|
|
815
822
|
* @experimental 21.0.0
|
|
816
823
|
*/
|
|
817
|
-
type
|
|
824
|
+
type WithoutFieldTree<T> = T & {
|
|
818
825
|
fieldTree: never;
|
|
819
826
|
};
|
|
827
|
+
/** @deprecated Use `WithoutFieldTree` instead */
|
|
828
|
+
type WithoutField<T> = WithoutFieldTree<T>;
|
|
820
829
|
/**
|
|
821
830
|
* Create a required error associated with the target field
|
|
822
831
|
* @param options The validation error options
|
|
823
832
|
*
|
|
824
833
|
* @experimental 21.0.0
|
|
825
834
|
*/
|
|
826
|
-
declare function requiredError(options:
|
|
835
|
+
declare function requiredError(options: WithFieldTree<ValidationErrorOptions>): RequiredValidationError;
|
|
827
836
|
/**
|
|
828
837
|
* Create a required error
|
|
829
838
|
* @param options The optional validation error options
|
|
@@ -831,7 +840,7 @@ declare function requiredError(options: WithField<ValidationErrorOptions>): Requ
|
|
|
831
840
|
* @category validation
|
|
832
841
|
* @experimental 21.0.0
|
|
833
842
|
*/
|
|
834
|
-
declare function requiredError(options?: ValidationErrorOptions):
|
|
843
|
+
declare function requiredError(options?: ValidationErrorOptions): WithoutFieldTree<RequiredValidationError>;
|
|
835
844
|
/**
|
|
836
845
|
* Create a min value error associated with the target field
|
|
837
846
|
* @param min The min value constraint
|
|
@@ -840,7 +849,7 @@ declare function requiredError(options?: ValidationErrorOptions): WithoutField<R
|
|
|
840
849
|
* @category validation
|
|
841
850
|
* @experimental 21.0.0
|
|
842
851
|
*/
|
|
843
|
-
declare function minError(min: number, options:
|
|
852
|
+
declare function minError(min: number, options: WithFieldTree<ValidationErrorOptions>): MinValidationError;
|
|
844
853
|
/**
|
|
845
854
|
* Create a min value error
|
|
846
855
|
* @param min The min value constraint
|
|
@@ -849,7 +858,7 @@ declare function minError(min: number, options: WithField<ValidationErrorOptions
|
|
|
849
858
|
* @category validation
|
|
850
859
|
* @experimental 21.0.0
|
|
851
860
|
*/
|
|
852
|
-
declare function minError(min: number, options?: ValidationErrorOptions):
|
|
861
|
+
declare function minError(min: number, options?: ValidationErrorOptions): WithoutFieldTree<MinValidationError>;
|
|
853
862
|
/**
|
|
854
863
|
* Create a max value error associated with the target field
|
|
855
864
|
* @param max The max value constraint
|
|
@@ -858,7 +867,7 @@ declare function minError(min: number, options?: ValidationErrorOptions): Withou
|
|
|
858
867
|
* @category validation
|
|
859
868
|
* @experimental 21.0.0
|
|
860
869
|
*/
|
|
861
|
-
declare function maxError(max: number, options:
|
|
870
|
+
declare function maxError(max: number, options: WithFieldTree<ValidationErrorOptions>): MaxValidationError;
|
|
862
871
|
/**
|
|
863
872
|
* Create a max value error
|
|
864
873
|
* @param max The max value constraint
|
|
@@ -867,7 +876,7 @@ declare function maxError(max: number, options: WithField<ValidationErrorOptions
|
|
|
867
876
|
* @category validation
|
|
868
877
|
* @experimental 21.0.0
|
|
869
878
|
*/
|
|
870
|
-
declare function maxError(max: number, options?: ValidationErrorOptions):
|
|
879
|
+
declare function maxError(max: number, options?: ValidationErrorOptions): WithoutFieldTree<MaxValidationError>;
|
|
871
880
|
/**
|
|
872
881
|
* Create a minLength error associated with the target field
|
|
873
882
|
* @param minLength The minLength constraint
|
|
@@ -876,7 +885,7 @@ declare function maxError(max: number, options?: ValidationErrorOptions): Withou
|
|
|
876
885
|
* @category validation
|
|
877
886
|
* @experimental 21.0.0
|
|
878
887
|
*/
|
|
879
|
-
declare function minLengthError(minLength: number, options:
|
|
888
|
+
declare function minLengthError(minLength: number, options: WithFieldTree<ValidationErrorOptions>): MinLengthValidationError;
|
|
880
889
|
/**
|
|
881
890
|
* Create a minLength error
|
|
882
891
|
* @param minLength The minLength constraint
|
|
@@ -885,7 +894,7 @@ declare function minLengthError(minLength: number, options: WithField<Validation
|
|
|
885
894
|
* @category validation
|
|
886
895
|
* @experimental 21.0.0
|
|
887
896
|
*/
|
|
888
|
-
declare function minLengthError(minLength: number, options?: ValidationErrorOptions):
|
|
897
|
+
declare function minLengthError(minLength: number, options?: ValidationErrorOptions): WithoutFieldTree<MinLengthValidationError>;
|
|
889
898
|
/**
|
|
890
899
|
* Create a maxLength error associated with the target field
|
|
891
900
|
* @param maxLength The maxLength constraint
|
|
@@ -894,7 +903,7 @@ declare function minLengthError(minLength: number, options?: ValidationErrorOpti
|
|
|
894
903
|
* @category validation
|
|
895
904
|
* @experimental 21.0.0
|
|
896
905
|
*/
|
|
897
|
-
declare function maxLengthError(maxLength: number, options:
|
|
906
|
+
declare function maxLengthError(maxLength: number, options: WithFieldTree<ValidationErrorOptions>): MaxLengthValidationError;
|
|
898
907
|
/**
|
|
899
908
|
* Create a maxLength error
|
|
900
909
|
* @param maxLength The maxLength constraint
|
|
@@ -903,7 +912,7 @@ declare function maxLengthError(maxLength: number, options: WithField<Validation
|
|
|
903
912
|
* @category validation
|
|
904
913
|
* @experimental 21.0.0
|
|
905
914
|
*/
|
|
906
|
-
declare function maxLengthError(maxLength: number, options?: ValidationErrorOptions):
|
|
915
|
+
declare function maxLengthError(maxLength: number, options?: ValidationErrorOptions): WithoutFieldTree<MaxLengthValidationError>;
|
|
907
916
|
/**
|
|
908
917
|
* Create a pattern matching error associated with the target field
|
|
909
918
|
* @param pattern The violated pattern
|
|
@@ -912,7 +921,7 @@ declare function maxLengthError(maxLength: number, options?: ValidationErrorOpti
|
|
|
912
921
|
* @category validation
|
|
913
922
|
* @experimental 21.0.0
|
|
914
923
|
*/
|
|
915
|
-
declare function patternError(pattern: RegExp, options:
|
|
924
|
+
declare function patternError(pattern: RegExp, options: WithFieldTree<ValidationErrorOptions>): PatternValidationError;
|
|
916
925
|
/**
|
|
917
926
|
* Create a pattern matching error
|
|
918
927
|
* @param pattern The violated pattern
|
|
@@ -921,7 +930,7 @@ declare function patternError(pattern: RegExp, options: WithField<ValidationErro
|
|
|
921
930
|
* @category validation
|
|
922
931
|
* @experimental 21.0.0
|
|
923
932
|
*/
|
|
924
|
-
declare function patternError(pattern: RegExp, options?: ValidationErrorOptions):
|
|
933
|
+
declare function patternError(pattern: RegExp, options?: ValidationErrorOptions): WithoutFieldTree<PatternValidationError>;
|
|
925
934
|
/**
|
|
926
935
|
* Create an email format error associated with the target field
|
|
927
936
|
* @param options The validation error options
|
|
@@ -929,7 +938,7 @@ declare function patternError(pattern: RegExp, options?: ValidationErrorOptions)
|
|
|
929
938
|
* @category validation
|
|
930
939
|
* @experimental 21.0.0
|
|
931
940
|
*/
|
|
932
|
-
declare function emailError(options:
|
|
941
|
+
declare function emailError(options: WithFieldTree<ValidationErrorOptions>): EmailValidationError;
|
|
933
942
|
/**
|
|
934
943
|
* Create an email format error
|
|
935
944
|
* @param options The optional validation error options
|
|
@@ -937,7 +946,7 @@ declare function emailError(options: WithField<ValidationErrorOptions>): EmailVa
|
|
|
937
946
|
* @category validation
|
|
938
947
|
* @experimental 21.0.0
|
|
939
948
|
*/
|
|
940
|
-
declare function emailError(options?: ValidationErrorOptions):
|
|
949
|
+
declare function emailError(options?: ValidationErrorOptions): WithoutFieldTree<EmailValidationError>;
|
|
941
950
|
/**
|
|
942
951
|
* Create a standard schema issue error associated with the target field
|
|
943
952
|
* @param issue The standard schema issue
|
|
@@ -946,7 +955,7 @@ declare function emailError(options?: ValidationErrorOptions): WithoutField<Emai
|
|
|
946
955
|
* @category validation
|
|
947
956
|
* @experimental 21.0.0
|
|
948
957
|
*/
|
|
949
|
-
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options:
|
|
958
|
+
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options: WithFieldTree<ValidationErrorOptions>): StandardSchemaValidationError;
|
|
950
959
|
/**
|
|
951
960
|
* Create a standard schema issue error
|
|
952
961
|
* @param issue The standard schema issue
|
|
@@ -955,7 +964,7 @@ declare function standardSchemaError(issue: StandardSchemaV1.Issue, options: Wit
|
|
|
955
964
|
* @category validation
|
|
956
965
|
* @experimental 21.0.0
|
|
957
966
|
*/
|
|
958
|
-
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions):
|
|
967
|
+
declare function standardSchemaError(issue: StandardSchemaV1.Issue, options?: ValidationErrorOptions): WithoutFieldTree<StandardSchemaValidationError>;
|
|
959
968
|
/**
|
|
960
969
|
* Common interface for all validation errors.
|
|
961
970
|
*
|
|
@@ -977,14 +986,23 @@ interface ValidationError {
|
|
|
977
986
|
}
|
|
978
987
|
declare namespace ValidationError {
|
|
979
988
|
/**
|
|
980
|
-
* Validation error with
|
|
989
|
+
* Validation error with an associated field tree.
|
|
981
990
|
*
|
|
982
991
|
* This is returned from field state, e.g., catField.errors() would be of a list of errors with
|
|
983
992
|
* `field: catField` bound to state.
|
|
984
993
|
*/
|
|
985
|
-
interface
|
|
994
|
+
interface WithFieldTree extends ValidationError {
|
|
986
995
|
/** The field associated with this error. */
|
|
987
996
|
readonly fieldTree: FieldTree<unknown>;
|
|
997
|
+
readonly formField?: FormField<unknown>;
|
|
998
|
+
}
|
|
999
|
+
/** @deprecated Use `ValidationError.WithFieldTree` instead */
|
|
1000
|
+
type WithField = WithFieldTree;
|
|
1001
|
+
/**
|
|
1002
|
+
* Validation error with an associated field tree and specific form field binding.
|
|
1003
|
+
*/
|
|
1004
|
+
interface WithFormField extends WithFieldTree {
|
|
1005
|
+
readonly formField: FormField<unknown>;
|
|
988
1006
|
}
|
|
989
1007
|
/**
|
|
990
1008
|
* Validation error with optional field.
|
|
@@ -992,19 +1010,24 @@ declare namespace ValidationError {
|
|
|
992
1010
|
* This is generally used in places where the result might have a field.
|
|
993
1011
|
* e.g., as a result of a `validateTree`, or when handling form submission.
|
|
994
1012
|
*/
|
|
995
|
-
interface
|
|
1013
|
+
interface WithOptionalFieldTree extends ValidationError {
|
|
996
1014
|
/** The field associated with this error. */
|
|
997
1015
|
readonly fieldTree?: FieldTree<unknown>;
|
|
998
1016
|
}
|
|
1017
|
+
/** @deprecated Use `ValidationError.WithOptionalFieldTree` instead */
|
|
1018
|
+
type WithOptionalField = WithOptionalFieldTree;
|
|
999
1019
|
/**
|
|
1000
1020
|
* Validation error with no field.
|
|
1001
1021
|
*
|
|
1002
1022
|
* This is used to strongly enforce that fields are not allowed in validation result.
|
|
1003
1023
|
*/
|
|
1004
|
-
interface
|
|
1024
|
+
interface WithoutFieldTree extends ValidationError {
|
|
1005
1025
|
/** The field associated with this error. */
|
|
1006
1026
|
readonly fieldTree?: never;
|
|
1027
|
+
readonly formField?: never;
|
|
1007
1028
|
}
|
|
1029
|
+
/** @deprecated Use `ValidationError.WithoutFieldTree` instead */
|
|
1030
|
+
type WithoutField = WithoutFieldTree;
|
|
1008
1031
|
}
|
|
1009
1032
|
/**
|
|
1010
1033
|
* Internal version of `NgValidationError`, we create this separately so we can change its type on
|
|
@@ -1265,11 +1288,11 @@ declare class LogicContainer {
|
|
|
1265
1288
|
/** Logic that determines if the field is read-only. */
|
|
1266
1289
|
readonly readonly: BooleanOrLogic;
|
|
1267
1290
|
/** Logic that produces synchronous validation errors for the field. */
|
|
1268
|
-
readonly syncErrors: ArrayMergeIgnoreLogic<ValidationError.
|
|
1291
|
+
readonly syncErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree, null>;
|
|
1269
1292
|
/** Logic that produces synchronous validation errors for the field's subtree. */
|
|
1270
|
-
readonly syncTreeErrors: ArrayMergeIgnoreLogic<ValidationError.
|
|
1293
|
+
readonly syncTreeErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree, null>;
|
|
1271
1294
|
/** Logic that produces asynchronous validation results (errors or 'pending'). */
|
|
1272
|
-
readonly asyncErrors: ArrayMergeIgnoreLogic<ValidationError.
|
|
1295
|
+
readonly asyncErrors: ArrayMergeIgnoreLogic<ValidationError.WithFieldTree | 'pending', null>;
|
|
1273
1296
|
/** A map of metadata keys to the `AbstractLogic` instances that compute their values. */
|
|
1274
1297
|
private readonly metadata;
|
|
1275
1298
|
/**
|
|
@@ -1366,9 +1389,9 @@ declare class LogicNodeBuilder extends AbstractLogicNodeBuilder {
|
|
|
1366
1389
|
addHiddenRule(logic: LogicFn<any, boolean>): void;
|
|
1367
1390
|
addDisabledReasonRule(logic: LogicFn<any, DisabledReason | undefined>): void;
|
|
1368
1391
|
addReadonlyRule(logic: LogicFn<any, boolean>): void;
|
|
1369
|
-
addSyncErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.
|
|
1370
|
-
addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.
|
|
1371
|
-
addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult<ValidationError.
|
|
1392
|
+
addSyncErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1393
|
+
addSyncTreeErrorRule(logic: LogicFn<any, ValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1394
|
+
addAsyncErrorRule(logic: LogicFn<any, AsyncValidationResult<ValidationError.WithFieldTree>>): void;
|
|
1372
1395
|
addMetadataRule<T>(key: MetadataKey<unknown, T, any>, logic: LogicFn<any, T>): void;
|
|
1373
1396
|
getChild(key: PropertyKey): LogicNodeBuilder;
|
|
1374
1397
|
hasLogic(builder: AbstractLogicNodeBuilder): boolean;
|
|
@@ -1619,7 +1642,7 @@ declare class FieldSubmitState {
|
|
|
1619
1642
|
*/
|
|
1620
1643
|
readonly selfSubmitting: WritableSignal<boolean>;
|
|
1621
1644
|
/** Submission errors that are associated with this field. */
|
|
1622
|
-
readonly submissionErrors: WritableSignal<readonly ValidationError.
|
|
1645
|
+
readonly submissionErrors: WritableSignal<readonly ValidationError.WithFieldTree[]>;
|
|
1623
1646
|
constructor(node: FieldNode);
|
|
1624
1647
|
/**
|
|
1625
1648
|
* Whether this form is currently in the process of being submitted.
|
|
@@ -1633,14 +1656,14 @@ interface ValidationState {
|
|
|
1633
1656
|
* The full set of synchronous tree errors visible to this field. This includes ones that are
|
|
1634
1657
|
* targeted at a descendant field rather than at this field.
|
|
1635
1658
|
*/
|
|
1636
|
-
rawSyncTreeErrors: Signal<ValidationError.
|
|
1659
|
+
rawSyncTreeErrors: Signal<ValidationError.WithFieldTree[]>;
|
|
1637
1660
|
/**
|
|
1638
1661
|
* The full set of synchronous errors for this field, including synchronous tree errors and submission
|
|
1639
1662
|
* errors. Submission errors are considered "synchronous" because they are imperatively added. From
|
|
1640
1663
|
* the perspective of the field state they are either there or not, they are never in a pending
|
|
1641
1664
|
* state.
|
|
1642
1665
|
*/
|
|
1643
|
-
syncErrors: Signal<ValidationError.
|
|
1666
|
+
syncErrors: Signal<ValidationError.WithFieldTree[]>;
|
|
1644
1667
|
/**
|
|
1645
1668
|
* Whether the field is considered valid according solely to its synchronous validators.
|
|
1646
1669
|
* Errors resulting from a previous submit attempt are also considered for this state.
|
|
@@ -1651,21 +1674,22 @@ interface ValidationState {
|
|
|
1651
1674
|
* targeted at a descendant field rather than at this field, as well as sentinel 'pending' values
|
|
1652
1675
|
* indicating that the validator is still running and an error could still occur.
|
|
1653
1676
|
*/
|
|
1654
|
-
rawAsyncErrors: Signal<(ValidationError.
|
|
1677
|
+
rawAsyncErrors: Signal<(ValidationError.WithFieldTree | 'pending')[]>;
|
|
1655
1678
|
/**
|
|
1656
1679
|
* The asynchronous tree errors visible to this field that are specifically targeted at this field
|
|
1657
1680
|
* rather than a descendant. This also includes all 'pending' sentinel values, since those could
|
|
1658
1681
|
* theoretically result in errors for this field.
|
|
1659
1682
|
*/
|
|
1660
|
-
asyncErrors: Signal<(ValidationError.
|
|
1683
|
+
asyncErrors: Signal<(ValidationError.WithFieldTree | 'pending')[]>;
|
|
1661
1684
|
/**
|
|
1662
1685
|
* The combined set of all errors that currently apply to this field.
|
|
1663
1686
|
*/
|
|
1664
|
-
errors: Signal<ValidationError.
|
|
1687
|
+
errors: Signal<ValidationError.WithFieldTree[]>;
|
|
1688
|
+
parseErrors: Signal<ValidationError.WithFormField[]>;
|
|
1665
1689
|
/**
|
|
1666
1690
|
* The combined set of all errors that currently apply to this field and its descendants.
|
|
1667
1691
|
*/
|
|
1668
|
-
errorSummary: Signal<ValidationError.
|
|
1692
|
+
errorSummary: Signal<ValidationError.WithFieldTree[]>;
|
|
1669
1693
|
/**
|
|
1670
1694
|
* Whether this field has any asynchronous validators still pending.
|
|
1671
1695
|
*/
|
|
@@ -1768,8 +1792,9 @@ declare class FieldNode implements FieldState<unknown> {
|
|
|
1768
1792
|
private _controlValue;
|
|
1769
1793
|
get controlValue(): Signal<unknown>;
|
|
1770
1794
|
get keyInParent(): Signal<string | number>;
|
|
1771
|
-
get errors(): Signal<ValidationError.
|
|
1772
|
-
get
|
|
1795
|
+
get errors(): Signal<ValidationError.WithFieldTree[]>;
|
|
1796
|
+
get parseErrors(): Signal<ValidationError.WithFormField[]>;
|
|
1797
|
+
get errorSummary(): Signal<ValidationError.WithFieldTree[]>;
|
|
1773
1798
|
get pending(): Signal<boolean>;
|
|
1774
1799
|
get valid(): Signal<boolean>;
|
|
1775
1800
|
get invalid(): Signal<boolean>;
|
|
@@ -2388,4 +2413,4 @@ declare function submit<TModel>(form: FieldTree<TModel>, action: (form: FieldTre
|
|
|
2388
2413
|
declare function schema<TValue>(fn: SchemaFn<TValue>): Schema<TValue>;
|
|
2389
2414
|
|
|
2390
2415
|
export { EmailValidationError, FORM_FIELD, FormField, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MetadataKey, MetadataReducer, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PathKind, PatternValidationError, REQUIRED, RequiredValidationError, SchemaPathRules, StandardSchemaValidationError, ValidationError, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit };
|
|
2391
|
-
export type { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, Debouncer, DisabledReason, FieldContext, FieldState, FieldTree, FieldValidator, FormFieldBindingOptions, FormOptions, ItemFieldContext, ItemType, LogicFn, MaybeFieldTree, MaybeSchemaPathTree, MetadataSetterType, OneOrMany, ReadonlyArrayLike, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SchemaPath, SchemaPathTree, SignalFormsConfig, Subfields, TreeValidationResult, TreeValidator, ValidationResult, ValidationSuccess, Validator, WithField, WithOptionalField, WithoutField };
|
|
2416
|
+
export type { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, Debouncer, DisabledReason, FieldContext, FieldState, FieldTree, FieldValidator, FormFieldBindingOptions, FormOptions, ItemFieldContext, ItemType, LogicFn, MaybeFieldTree, MaybeSchemaPathTree, MetadataSetterType, OneOrMany, ReadonlyArrayLike, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SchemaPath, SchemaPathTree, SignalFormsConfig, Subfields, TreeValidationResult, TreeValidator, ValidationResult, ValidationSuccess, Validator, WithField, WithFieldTree, WithOptionalField, WithOptionalFieldTree, WithoutField, WithoutFieldTree };
|
package/types/forms.d.ts
CHANGED