@angular/forms 21.0.0-rc.2 → 21.0.0-rc.3

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/types/forms.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v21.0.0-rc.2
2
+ * @license Angular v21.0.0-rc.3
3
3
  * (c) 2010-2025 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
@@ -4020,12 +4020,12 @@ declare class FormGroupName extends AbstractFormGroupDirective implements OnInit
4020
4020
  *
4021
4021
  * Syncs a nested `FormArray` to a DOM element.
4022
4022
  *
4023
- * This directive is designed to be used with a parent `FormGroupDirective`/`FormGroupArray` (selector:
4023
+ * This directive is designed to be used with a parent `FormGroupDirective`/`FormArrayDirective` (selector:
4024
4024
  * `[formGroup]`/`[formArray]`).
4025
4025
  *
4026
4026
  * It accepts the string name of the nested `FormArray` you want to link, and
4027
4027
  * will look for a `FormArray` registered with that name in the parent
4028
- * `FormGroup`/`FormArray` instance you passed into `FormGroupDirective`/`FormGroupArray`.
4028
+ * `FormGroup`/`FormArray` instance you passed into `FormGroupDirective`/`FormArrayDirective`.
4029
4029
  *
4030
4030
  * @see [Reactive Forms Guide](guide/forms/reactive-forms)
4031
4031
  * @see {@link AbstractControl}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @license Angular v21.0.0-rc.3
3
+ * (c) 2010-2025 Google LLC. https://angular.dev/
4
+ * License: MIT
5
+ */
6
+
7
+ import { WritableSignal } from '@angular/core';
8
+ import { FormOptions, FieldTree, SchemaOrSchemaFn, ValidationError } from './_structure-chunk.js';
9
+ import { AbstractControl } from '@angular/forms';
10
+ import '@standard-schema/spec';
11
+
12
+ /**
13
+ * Options that may be specified when creating a compat form.
14
+ *
15
+ * @category interop
16
+ * @experimental 21.0.0
17
+ */
18
+ type CompatFormOptions = Omit<FormOptions, 'adapter'>;
19
+ /**
20
+ * Creates a compatibility form wrapped around the given model data.
21
+ *
22
+ * `compatForm` is a version of the `form` function that is designed for backwards
23
+ * compatibility with Reactive forms by accepting Reactive controls as a part of the data.
24
+ *
25
+ * @example
26
+ * ```
27
+ * const lastName = new FormControl('lastName');
28
+ *
29
+ * const nameModel = signal({
30
+ * first: '',
31
+ * last: lastName
32
+ * });
33
+ *
34
+ * const nameForm = compatForm(nameModel, (name) => {
35
+ * required(name.first);
36
+ * });
37
+ *
38
+ * nameForm.last().value(); // lastName, not FormControl
39
+ *
40
+ * @param model A writable signal that contains the model data for the form. The resulting field
41
+ * structure will match the shape of the model and any changes to the form data will be written to
42
+ * the model.
43
+
44
+ * @category interop
45
+ * @experimental 21.0.0
46
+ */
47
+ declare function compatForm<TModel>(model: WritableSignal<TModel>): FieldTree<TModel>;
48
+ /**
49
+ * Creates a compatibility form wrapped around the given model data.
50
+ *
51
+ * `compatForm` is a version of the `form` function that is designed for backwards
52
+ * compatibility with Reactive forms by accepting Reactive controls as a part of the data.
53
+ *
54
+ * @example
55
+ * ```
56
+ * const lastName = new FormControl('lastName');
57
+ *
58
+ * const nameModel = signal({
59
+ * first: '',
60
+ * last: lastName
61
+ * });
62
+ *
63
+ * const nameForm = compatForm(nameModel, (name) => {
64
+ * required(name.first);
65
+ * });
66
+ *
67
+ * nameForm.last().value(); // lastName, not FormControl
68
+ *
69
+ * @param model A writable signal that contains the model data for the form. The resulting field
70
+ * structure will match the shape of the model and any changes to the form data will be written to
71
+ * the model.
72
+ * @param schemaOrOptions The second argument can be either
73
+ * 1. A schema or a function used to specify logic for the form (e.g. validation, disabled fields, etc.).
74
+ * When passing a schema, the form options can be passed as a third argument if needed.
75
+ * 2. The form options (excluding adapter, since it's provided).
76
+ *
77
+ * @category interop
78
+ * @experimental 21.0.0
79
+ */
80
+ declare function compatForm<TModel>(model: WritableSignal<TModel>, schemaOrOptions: SchemaOrSchemaFn<TModel> | CompatFormOptions): FieldTree<TModel>;
81
+ /**
82
+ * Creates a compatibility form wrapped around the given model data.
83
+ *
84
+ * `compatForm` is a version of the `form` function that is designed for backwards
85
+ * compatibility with Reactive forms by accepting Reactive controls as a part of the data.
86
+ *
87
+ * @example
88
+ * ```
89
+ * const lastName = new FormControl('lastName');
90
+ *
91
+ * const nameModel = signal({
92
+ * first: '',
93
+ * last: lastName
94
+ * });
95
+ *
96
+ * const nameForm = compatForm(nameModel, (name) => {
97
+ * required(name.first);
98
+ * });
99
+ *
100
+ * nameForm.last().value(); // lastName, not FormControl
101
+ *
102
+ * @param model A writable signal that contains the model data for the form. The resulting field
103
+ * structure will match the shape of the model and any changes to the form data will be written to
104
+ * the model.
105
+ * @param schemaOrOptions A schema or a function used to specify logic for the form (e.g. validation, disabled fields, etc.).
106
+ * When passing a schema, the form options can be passed as a third argument if needed.
107
+ * @param options The form options (excluding adapter, since it's provided).
108
+ *
109
+ * @category interop
110
+ * @experimental 21.0.0
111
+ */
112
+ declare function compatForm<TModel>(model: WritableSignal<TModel>, schema: SchemaOrSchemaFn<TModel>, options: CompatFormOptions): FieldTree<TModel>;
113
+
114
+ /**
115
+ * An error used for compat errors.
116
+ *
117
+ * @experimental 21.0.0
118
+ * @category interop
119
+ */
120
+ declare class CompatValidationError<T = unknown> implements ValidationError {
121
+ readonly kind: string;
122
+ readonly control: AbstractControl;
123
+ readonly field: FieldTree<unknown>;
124
+ readonly context: T;
125
+ readonly message?: string;
126
+ constructor({ context, kind, control }: {
127
+ context: T;
128
+ kind: string;
129
+ control: AbstractControl;
130
+ });
131
+ }
132
+
133
+ export { CompatValidationError, compatForm };
134
+ export type { CompatFormOptions };