@angular/forms 21.1.0-next.3 → 21.1.0-next.4
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 +20 -20
- 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 +25 -11
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +17 -17
- package/fesm2022/signals.mjs.map +1 -1
- package/package.json +6 -6
- package/types/_structure-chunk.d.ts +62 -17
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +2 -2
- package/types/signals.d.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.1.0-next.
|
|
2
|
+
* @license Angular v21.1.0-next.4
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
@@ -311,7 +311,7 @@ type SubmittedStatus = 'unsubmitted' | 'submitted' | 'submitting';
|
|
|
311
311
|
*/
|
|
312
312
|
interface DisabledReason {
|
|
313
313
|
/** The field that is disabled. */
|
|
314
|
-
readonly
|
|
314
|
+
readonly fieldTree: FieldTree<unknown>;
|
|
315
315
|
/** A user-facing message describing the reason for the disablement. */
|
|
316
316
|
readonly message?: string;
|
|
317
317
|
}
|
|
@@ -576,9 +576,42 @@ type SchemaPathTree<TModel, TPathKind extends PathKind = PathKind.Root> = ([TMod
|
|
|
576
576
|
*/
|
|
577
577
|
type MaybeSchemaPathTree<TModel, TPathKind extends PathKind = PathKind.Root> = (TModel & undefined) | SchemaPathTree<Exclude<TModel, undefined>, TPathKind>;
|
|
578
578
|
/**
|
|
579
|
-
*
|
|
579
|
+
* A reusable schema that defines behavior and rules for a form.
|
|
580
580
|
*
|
|
581
|
-
*
|
|
581
|
+
* A `Schema` encapsulates form logic such as validation rules, disabled states, readonly states,
|
|
582
|
+
* and other field-level behaviors.
|
|
583
|
+
*
|
|
584
|
+
* Unlike raw {@link SchemaFn}, a `Schema` is created using
|
|
585
|
+
* the {@link schema} function and is cached per-form, even when applied to multiple fields.
|
|
586
|
+
*
|
|
587
|
+
* ### Creating a reusable schema
|
|
588
|
+
*
|
|
589
|
+
* ```typescript
|
|
590
|
+
* interface Address {
|
|
591
|
+
* street: string;
|
|
592
|
+
* city: string;
|
|
593
|
+
* }
|
|
594
|
+
*
|
|
595
|
+
* // Create a reusable schema for address fields
|
|
596
|
+
* const addressSchema = schema<Address>((p) => {
|
|
597
|
+
* required(p.street);
|
|
598
|
+
* required(p.city);
|
|
599
|
+
* });
|
|
600
|
+
*
|
|
601
|
+
* // Apply the schema to multiple forms
|
|
602
|
+
* const shippingForm = form(shippingModel, addressSchema, {injector});
|
|
603
|
+
* const billingForm = form(billingModel, addressSchema, {injector});
|
|
604
|
+
* ```
|
|
605
|
+
*
|
|
606
|
+
* ### Passing a schema to a form
|
|
607
|
+
*
|
|
608
|
+
* A schema can also be passed as a second argument to the {@link form} function.
|
|
609
|
+
*
|
|
610
|
+
* ```typescript
|
|
611
|
+
* readonly userForm = form(addressModel, addressSchema);
|
|
612
|
+
* ```
|
|
613
|
+
*
|
|
614
|
+
* @template TModel Data type.
|
|
582
615
|
*
|
|
583
616
|
* @category types
|
|
584
617
|
* @experimental 21.0.0
|
|
@@ -587,9 +620,21 @@ type Schema<in TModel> = {
|
|
|
587
620
|
[ɵɵTYPE]: SchemaFn<TModel, PathKind.Root>;
|
|
588
621
|
};
|
|
589
622
|
/**
|
|
590
|
-
*
|
|
623
|
+
* A function that receives a {@link SchemaPathTree} and applies rules to fields.
|
|
591
624
|
*
|
|
592
|
-
*
|
|
625
|
+
* A `SchemaFn` can be passed directly to {@link form} or to the {@link schema} function to create a
|
|
626
|
+
* cached {@link Schema}.
|
|
627
|
+
*
|
|
628
|
+
* ```typescript
|
|
629
|
+
* const userFormSchema: SchemaFn<User> = (p) => {
|
|
630
|
+
* required(p.name);
|
|
631
|
+
* disabled(p.email, ({valueOf}) => valueOf(p.name) === '');
|
|
632
|
+
* };
|
|
633
|
+
*
|
|
634
|
+
* const f = form(userModel, userFormSchema, {injector});
|
|
635
|
+
* ```
|
|
636
|
+
*
|
|
637
|
+
* @template TModel Data type.
|
|
593
638
|
* @template TPathKind The kind of path this schema function can be bound to.
|
|
594
639
|
*
|
|
595
640
|
* @category types
|
|
@@ -597,7 +642,7 @@ type Schema<in TModel> = {
|
|
|
597
642
|
*/
|
|
598
643
|
type SchemaFn<TModel, TPathKind extends PathKind = PathKind.Root> = (p: SchemaPathTree<TModel, TPathKind>) => void;
|
|
599
644
|
/**
|
|
600
|
-
* A
|
|
645
|
+
* A {@link Schema} or {@link SchemaFn}.
|
|
601
646
|
*
|
|
602
647
|
* @template TModel The type of data stored in the form that this schema function is attached to.
|
|
603
648
|
* @template TPathKind The kind of path this schema function can be bound to.
|
|
@@ -671,7 +716,7 @@ interface RootFieldContext<TValue> {
|
|
|
671
716
|
/** The state of the current field. */
|
|
672
717
|
readonly state: FieldState<TValue>;
|
|
673
718
|
/** The current field. */
|
|
674
|
-
readonly
|
|
719
|
+
readonly fieldTree: FieldTree<TValue>;
|
|
675
720
|
/** Gets the value of the field represented by the given path. */
|
|
676
721
|
valueOf<PValue>(p: SchemaPath<PValue, SchemaPathRules>): PValue;
|
|
677
722
|
/** Gets the state of the field represented by the given path. */
|
|
@@ -734,7 +779,7 @@ interface ValidationErrorOptions {
|
|
|
734
779
|
* @experimental 21.0.0
|
|
735
780
|
*/
|
|
736
781
|
type WithField<T> = T & {
|
|
737
|
-
|
|
782
|
+
fieldTree: FieldTree<unknown>;
|
|
738
783
|
};
|
|
739
784
|
/**
|
|
740
785
|
* A type that allows the given type `T` to optionally have a `field` property.
|
|
@@ -742,8 +787,8 @@ type WithField<T> = T & {
|
|
|
742
787
|
*
|
|
743
788
|
* @experimental 21.0.0
|
|
744
789
|
*/
|
|
745
|
-
type WithOptionalField<T> = Omit<T, '
|
|
746
|
-
|
|
790
|
+
type WithOptionalField<T> = Omit<T, 'fieldTree'> & {
|
|
791
|
+
fieldTree?: FieldTree<unknown>;
|
|
747
792
|
};
|
|
748
793
|
/**
|
|
749
794
|
* A type that ensures the given type `T` does not have a `field` property.
|
|
@@ -752,7 +797,7 @@ type WithOptionalField<T> = Omit<T, 'field'> & {
|
|
|
752
797
|
* @experimental 21.0.0
|
|
753
798
|
*/
|
|
754
799
|
type WithoutField<T> = T & {
|
|
755
|
-
|
|
800
|
+
fieldTree: never;
|
|
756
801
|
};
|
|
757
802
|
/**
|
|
758
803
|
* Create a required error associated with the target field
|
|
@@ -935,7 +980,7 @@ declare namespace ValidationError {
|
|
|
935
980
|
*/
|
|
936
981
|
interface WithField extends ValidationError {
|
|
937
982
|
/** The field associated with this error. */
|
|
938
|
-
readonly
|
|
983
|
+
readonly fieldTree: FieldTree<unknown>;
|
|
939
984
|
}
|
|
940
985
|
/**
|
|
941
986
|
* Validation error with optional field.
|
|
@@ -945,7 +990,7 @@ declare namespace ValidationError {
|
|
|
945
990
|
*/
|
|
946
991
|
interface WithOptionalField extends ValidationError {
|
|
947
992
|
/** The field associated with this error. */
|
|
948
|
-
readonly
|
|
993
|
+
readonly fieldTree?: FieldTree<unknown>;
|
|
949
994
|
}
|
|
950
995
|
/**
|
|
951
996
|
* Validation error with no field.
|
|
@@ -973,7 +1018,7 @@ declare class CustomValidationError implements ValidationError {
|
|
|
973
1018
|
/** Identifies the kind of error. */
|
|
974
1019
|
readonly kind: string;
|
|
975
1020
|
/** The field associated with this error. */
|
|
976
|
-
readonly
|
|
1021
|
+
readonly fieldTree: FieldTree<unknown>;
|
|
977
1022
|
/** Human readable error message. */
|
|
978
1023
|
readonly message?: string;
|
|
979
1024
|
constructor(options?: ValidationErrorOptions);
|
|
@@ -990,7 +1035,7 @@ declare abstract class _NgValidationError implements ValidationError {
|
|
|
990
1035
|
/** Identifies the kind of error. */
|
|
991
1036
|
readonly kind: string;
|
|
992
1037
|
/** The field associated with this error. */
|
|
993
|
-
readonly
|
|
1038
|
+
readonly fieldTree: FieldTree<unknown>;
|
|
994
1039
|
/** Human readable error message. */
|
|
995
1040
|
readonly message?: string;
|
|
996
1041
|
constructor(options?: ValidationErrorOptions);
|
|
@@ -1115,7 +1160,7 @@ type NgValidationError = RequiredValidationError | MinValidationError | MaxValid
|
|
|
1115
1160
|
interface SignalFormsConfig {
|
|
1116
1161
|
/** A map of CSS class names to predicate functions that determine when to apply them. */
|
|
1117
1162
|
classes?: {
|
|
1118
|
-
[className: string]: (state:
|
|
1163
|
+
[className: string]: (state: Field<unknown>) => boolean;
|
|
1119
1164
|
};
|
|
1120
1165
|
}
|
|
1121
1166
|
/**
|
package/types/forms.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.1.0-next.
|
|
2
|
+
* @license Angular v21.1.0-next.4
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
@@ -121,7 +121,7 @@ declare function compatForm<TModel>(model: WritableSignal<TModel>, schema: Schem
|
|
|
121
121
|
declare class CompatValidationError<T = unknown> implements ValidationError {
|
|
122
122
|
readonly kind: string;
|
|
123
123
|
readonly control: AbstractControl;
|
|
124
|
-
readonly
|
|
124
|
+
readonly fieldTree: FieldTree<unknown>;
|
|
125
125
|
readonly context: T;
|
|
126
126
|
readonly message?: string;
|
|
127
127
|
constructor({ context, kind, control }: {
|
package/types/signals.d.ts
CHANGED