@angular/forms 21.2.0-next.1 → 21.2.0-next.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.2.0-next.1
2
+ * @license Angular v21.2.0-next.3
3
3
  * (c) 2010-2026 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @license Angular v21.2.0-next.1
2
+ * @license Angular v21.2.0-next.3
3
3
  * (c) 2010-2026 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import { WritableSignal } from '@angular/core';
8
- import { FormOptions, FieldTree, SchemaOrSchemaFn, ValidationError, SignalFormsConfig } from './_structure-chunk.js';
9
- import { AbstractControl } from '@angular/forms';
7
+ import { WritableSignal, EventEmitter } from '@angular/core';
8
+ import { FormOptions, FieldTree, SchemaOrSchemaFn, ValidationError, SignalFormsConfig, SchemaFn } from './_structure-chunk.js';
9
+ import { AbstractControl, FormControlStatus, FormControlState } from '@angular/forms';
10
10
  import '@standard-schema/spec';
11
11
 
12
12
  /**
@@ -15,7 +15,7 @@ import '@standard-schema/spec';
15
15
  * @category interop
16
16
  * @experimental 21.0.0
17
17
  */
18
- type CompatFormOptions = Omit<FormOptions, 'adapter'>;
18
+ type CompatFormOptions<TModel> = Omit<FormOptions<TModel>, 'adapter'>;
19
19
  /**
20
20
  * Creates a compatibility form wrapped around the given model data.
21
21
  *
@@ -78,7 +78,7 @@ declare function compatForm<TModel>(model: WritableSignal<TModel>): FieldTree<TM
78
78
  * @category interop
79
79
  * @experimental 21.0.0
80
80
  */
81
- declare function compatForm<TModel>(model: WritableSignal<TModel>, schemaOrOptions: SchemaOrSchemaFn<TModel> | CompatFormOptions): FieldTree<TModel>;
81
+ declare function compatForm<TModel>(model: WritableSignal<TModel>, schemaOrOptions: SchemaOrSchemaFn<TModel> | CompatFormOptions<TModel>): FieldTree<TModel>;
82
82
  /**
83
83
  * Creates a compatibility form wrapped around the given model data.
84
84
  *
@@ -110,7 +110,7 @@ declare function compatForm<TModel>(model: WritableSignal<TModel>, schemaOrOptio
110
110
  * @category interop
111
111
  * @experimental 21.0.0
112
112
  */
113
- declare function compatForm<TModel>(model: WritableSignal<TModel>, schema: SchemaOrSchemaFn<TModel>, options: CompatFormOptions): FieldTree<TModel>;
113
+ declare function compatForm<TModel>(model: WritableSignal<TModel>, schema: SchemaOrSchemaFn<TModel>, options: CompatFormOptions<TModel>): FieldTree<TModel>;
114
114
 
115
115
  /**
116
116
  * An error used for compat errors.
@@ -139,5 +139,128 @@ declare class CompatValidationError<T = unknown> implements ValidationError {
139
139
  */
140
140
  declare const NG_STATUS_CLASSES: SignalFormsConfig['classes'];
141
141
 
142
- export { CompatValidationError, NG_STATUS_CLASSES, compatForm };
142
+ /** Options used to update the control value. */
143
+ type ValueUpdateOptions = {
144
+ onlySelf?: boolean;
145
+ emitEvent?: boolean;
146
+ emitModelToViewChange?: boolean;
147
+ emitViewToModelChange?: boolean;
148
+ };
149
+ /**
150
+ * A `FormControl` that is backed by signal forms rules.
151
+ *
152
+ * This class provides a bridge between Signal Forms and Reactive Forms, allowing
153
+ * signal-based controls to be used within a standard `FormGroup` or `FormArray`.
154
+ *
155
+ * A control could be created using signal forms, and integrated with an existing FormGroup
156
+ * propagating all the statuses and validity.
157
+ *
158
+ * @usageNotes
159
+ *
160
+ * ### Basic usage
161
+ *
162
+ * ```angular-ts
163
+ * const form = new FormGroup({
164
+ * // You can create SignalFormControl with signal form rules, and add it to a FormGroup.
165
+ * name: new SignalFormControl('Alice', p => {
166
+ * required(p);
167
+ * }),
168
+ * age: new FormControl(25),
169
+ * });
170
+ * ```
171
+ * In the template you can get the underlying `fieldTree` and bind it:
172
+ *
173
+ * ```angular-html
174
+ * <form [formGroup]="form">
175
+ * <input [formField]="nameControl.fieldTree" />
176
+ * <input formControlName="age" />
177
+ * </form>
178
+ * ```
179
+ *
180
+ * @experimental
181
+ */
182
+ declare class SignalFormControl<T> extends AbstractControl {
183
+ /** Source FieldTree. */
184
+ readonly fieldTree: FieldTree<T>;
185
+ /** The raw signal driving the control value. */
186
+ readonly sourceValue: WritableSignal<T>;
187
+ private readonly fieldState;
188
+ private readonly initialValue;
189
+ private pendingParentNotifications;
190
+ private readonly onChangeCallbacks;
191
+ private readonly onDisabledChangeCallbacks;
192
+ readonly valueChanges: EventEmitter<T>;
193
+ readonly statusChanges: EventEmitter<FormControlStatus>;
194
+ constructor(value: T, schemaOrOptions?: SchemaFn<T> | FormOptions<T>, options?: FormOptions<T>);
195
+ /**
196
+ * Defines properties using closure-safe names to prevent issues with property renaming optimizations.
197
+ *
198
+ * AbstractControl have `value` and `errors` as readonly prop, which doesn't allow getters.
199
+ **/
200
+ private defineCompatProperties;
201
+ private emitControlEvent;
202
+ setValue(value: any, options?: ValueUpdateOptions): void;
203
+ patchValue(value: any, options?: ValueUpdateOptions): void;
204
+ private updateValue;
205
+ registerOnChange(fn: (value?: any, emitModelEvent?: boolean) => void): void;
206
+ registerOnDisabledChange(fn: (isDisabled: boolean) => void): void;
207
+ getRawValue(): T;
208
+ reset(value?: T | FormControlState<T>, options?: ValueUpdateOptions): void;
209
+ private scheduleParentUpdate;
210
+ private notifyParentUnlessPending;
211
+ private updateParentValueAndValidity;
212
+ private propagateToParent;
213
+ get status(): FormControlStatus;
214
+ get valid(): boolean;
215
+ get invalid(): boolean;
216
+ get pending(): boolean;
217
+ get disabled(): boolean;
218
+ get enabled(): boolean;
219
+ get dirty(): boolean;
220
+ set dirty(_: boolean);
221
+ get pristine(): boolean;
222
+ set pristine(_: boolean);
223
+ get touched(): boolean;
224
+ set touched(_: boolean);
225
+ get untouched(): boolean;
226
+ set untouched(_: boolean);
227
+ markAsTouched(opts?: {
228
+ onlySelf?: boolean;
229
+ }): void;
230
+ markAsDirty(opts?: {
231
+ onlySelf?: boolean;
232
+ }): void;
233
+ markAsPristine(opts?: {
234
+ onlySelf?: boolean;
235
+ }): void;
236
+ markAsUntouched(opts?: {
237
+ onlySelf?: boolean;
238
+ }): void;
239
+ updateValueAndValidity(_opts?: Object): void;
240
+ disable(_opts?: {
241
+ onlySelf?: boolean;
242
+ emitEvent?: boolean;
243
+ }): void;
244
+ enable(_opts?: {
245
+ onlySelf?: boolean;
246
+ emitEvent?: boolean;
247
+ }): void;
248
+ setValidators(_validators: any): void;
249
+ setAsyncValidators(_validators: any): void;
250
+ addValidators(_validators: any): void;
251
+ addAsyncValidators(_validators: any): void;
252
+ removeValidators(_validators: any): void;
253
+ removeAsyncValidators(_validators: any): void;
254
+ clearValidators(): void;
255
+ clearAsyncValidators(): void;
256
+ setErrors(_errors: any, _opts?: {
257
+ emitEvent?: boolean;
258
+ }): void;
259
+ markAsPending(_opts?: {
260
+ onlySelf?: boolean;
261
+ emitEvent?: boolean;
262
+ }): void;
263
+ }
264
+
265
+ export { CompatValidationError, NG_STATUS_CLASSES, SignalFormControl, compatForm };
143
266
  export type { CompatFormOptions };
@@ -1,15 +1,16 @@
1
1
  /**
2
- * @license Angular v21.2.0-next.1
2
+ * @license Angular v21.2.0-next.3
3
3
  * (c) 2010-2026 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import { Signal, ResourceRef, InputSignal, InputSignalWithTransform, ModelSignal, OutputRef } from '@angular/core';
8
- import { PathKind, SchemaPath, SchemaPathRules, LogicFn, OneOrMany, ValidationError, SchemaPathTree, FieldValidator, FieldContext, TreeValidationResult, TreeValidator, WithOptionalFieldTree, DisabledReason, Debouncer } from './_structure-chunk.js';
9
- export { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, EmailValidationError, FORM_FIELD, FieldState, FieldTree, FormField, FormFieldBindingOptions, 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, ValidationResult, ValidationSuccess, Validator, WithField, WithFieldTree, WithOptionalField, WithoutField, WithoutFieldTree, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit } from './_structure-chunk.js';
10
- import { StandardSchemaV1 } from '@standard-schema/spec';
7
+ import * as i0 from '@angular/core';
8
+ import { Signal, ResourceRef, InputSignal, InputSignalWithTransform, ModelSignal, OutputRef, WritableSignal } from '@angular/core';
9
+ import { PathKind, SchemaPath, SchemaPathRules, LogicFn, OneOrMany, ValidationError, FieldValidator, FieldContext, TreeValidationResult, TreeValidator, WithOptionalFieldTree, DisabledReason, Debouncer, FieldTree } from './_structure-chunk.js';
10
+ export { AsyncValidationResult, BaseNgValidationError, ChildFieldContext, CompatFieldState, CompatSchemaPath, EmailValidationError, FORM_FIELD, FieldState, FormField, FormFieldBindingOptions, FormOptions, FormSubmitOptions, IgnoreUnknownProperties, ItemFieldContext, ItemType, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MaybeFieldTree, MaybeSchemaPathTree, MetadataKey, MetadataReducer, MetadataSetterType, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PatternValidationError, REQUIRED, ReadonlyArrayLike, RemoveStringIndexUnknownKey, RequiredValidationError, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SchemaPathTree, SignalFormsConfig, StandardSchemaValidationError, Subfields, ValidationErrorOptions, ValidationResult, ValidationSuccess, Validator, WithField, WithFieldTree, WithOptionalField, WithoutField, WithoutFieldTree, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit, validateStandardSchema, ɵNgFieldDirective } from './_structure-chunk.js';
11
11
  import { HttpResourceRequest, HttpResourceOptions } from '@angular/common/http';
12
12
  import '@angular/forms';
13
+ import '@standard-schema/spec';
13
14
 
14
15
  /**
15
16
  * Adds logic to a field to conditionally disable it. A disabled field does not contribute to the
@@ -216,41 +217,6 @@ declare function required<TValue, TPathKind extends PathKind = PathKind.Root>(pa
216
217
  when?: NoInfer<LogicFn<TValue, boolean, TPathKind>>;
217
218
  }): void;
218
219
 
219
- /**
220
- * Utility type that removes a string index key when its value is `unknown`,
221
- * i.e. `{[key: string]: unknown}`. It allows specific string keys to pass through, even if their
222
- * value is `unknown`, e.g. `{key: unknown}`.
223
- *
224
- * @experimental 21.0.0
225
- */
226
- type RemoveStringIndexUnknownKey<K, V> = string extends K ? unknown extends V ? never : K : K;
227
- /**
228
- * Utility type that recursively ignores unknown string index properties on the given object.
229
- * We use this on the `TSchema` type in `validateStandardSchema` in order to accommodate Zod's
230
- * `looseObject` which includes `{[key: string]: unknown}` as part of the type.
231
- *
232
- * @experimental 21.0.0
233
- */
234
- type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
235
- [K in keyof T as RemoveStringIndexUnknownKey<K, T[K]>]: IgnoreUnknownProperties<T[K]>;
236
- } : T;
237
- /**
238
- * Validates a field using a `StandardSchemaV1` compatible validator (e.g. a Zod validator).
239
- *
240
- * See https://github.com/standard-schema/standard-schema for more about standard schema.
241
- *
242
- * @param path The `FieldPath` to the field to validate.
243
- * @param schema The standard schema compatible validator to use for validation.
244
- * @template TSchema The type validated by the schema. This may be either the full `TValue` type,
245
- * or a partial of it.
246
- * @template TValue The type of value stored in the field being validated.
247
- *
248
- * @see [Signal Form Schema Validation](guide/forms/signals/validation#integration-with-schema-validation-libraries)
249
- * @category validation
250
- * @experimental 21.0.0
251
- */
252
- declare function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProperties<TSchema>>(path: SchemaPath<TModel> & SchemaPathTree<TModel>, schema: StandardSchemaV1<TSchema>): void;
253
-
254
220
  /**
255
221
  * Adds logic to a field to determine if the field has validation errors.
256
222
  *
@@ -504,12 +470,6 @@ interface FormUiControl<TValue> {
504
470
  * will automatically bind the value patterns from the bound field to this input.
505
471
  */
506
472
  readonly pattern?: InputSignal<readonly RegExp[]> | InputSignalWithTransform<readonly RegExp[], unknown>;
507
- /**
508
- * A signal containing the current parse errors for the control.
509
- * This allows the control to communicate to the form that there are additional validation errors
510
- * beyond those produced by the schema, due to being unable to parse the user's input.
511
- */
512
- readonly parseErrors?: Signal<ValidationError.WithoutFieldTree[]>;
513
473
  /**
514
474
  * Focuses the UI control.
515
475
  *
@@ -583,5 +543,104 @@ interface FormCheckboxControl extends FormUiControl<boolean> {
583
543
  */
584
544
  declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, durationOrDebouncer: number | Debouncer<TValue, TPathKind>): void;
585
545
 
586
- export { Debouncer, DisabledReason, FieldContext, FieldValidator, LogicFn, OneOrMany, PathKind, SchemaPath, SchemaPathRules, SchemaPathTree, TreeValidationResult, TreeValidator, ValidationError, WithOptionalFieldTree, debounce, disabled, email, hidden, max, maxLength, min, minLength, pattern, readonly, required, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
587
- export type { AsyncValidatorOptions, FormCheckboxControl, FormUiControl, FormValueControl, HttpValidatorOptions, IgnoreUnknownProperties, MapToErrorsFn, RemoveStringIndexUnknownKey };
546
+ /**
547
+ * Options for `transformedValue`.
548
+ *
549
+ * @experimental 21.2.0
550
+ */
551
+ interface TransformedValueOptions<TValue, TRaw> {
552
+ /**
553
+ * Parse the raw value into the model value.
554
+ *
555
+ * Should return an object containing the parsed result, which may contain:
556
+ * - `value`: The parsed model value. If `undefined`, the model will not be updated.
557
+ * - `errors`: Any parse errors encountered. If `undefined`, no errors are reported.
558
+ */
559
+ parse: (rawValue: TRaw) => {
560
+ value?: TValue;
561
+ errors?: readonly ValidationError.WithoutFieldTree[];
562
+ };
563
+ /**
564
+ * Format the model value into the raw value.
565
+ */
566
+ format: (value: TValue) => TRaw;
567
+ }
568
+ /**
569
+ * A writable signal representing a "raw" UI value that is synchronized with a model signal
570
+ * via parse/format transformations.
571
+ *
572
+ * @category control
573
+ * @experimental 21.2.0
574
+ */
575
+ interface TransformedValueSignal<TRaw> extends WritableSignal<TRaw> {
576
+ /**
577
+ * The current parse errors resulting from the last transformation.
578
+ */
579
+ readonly parseErrors: Signal<readonly ValidationError.WithoutFieldTree[]>;
580
+ }
581
+ /**
582
+ * Creates a writable signal representing a "raw" UI value that is transformed to/from a model
583
+ * value via `parse` and `format` functions.
584
+ *
585
+ * This utility simplifies the creation of custom form controls that parse a user-facing value
586
+ * representation into an underlying model value. For example, a numeric input that displays and
587
+ * accepts string values but stores a number.
588
+ *
589
+ * @param value The model signal to synchronize with.
590
+ * @param options Configuration including `parse` and `format` functions.
591
+ * @returns A `TransformedValueSignal` representing the raw value with parse error tracking.
592
+ * @experimental 21.2.0
593
+ *
594
+ * @example
595
+ * ```ts
596
+ * @Component({
597
+ * selector: 'number-input',
598
+ * template: `<input [value]="rawValue()" (input)="rawValue.set($event.target.value)" />`,
599
+ * })
600
+ * export class NumberInput implements FormValueControl<number | null> {
601
+ * readonly value = model.required<number | null>();
602
+ *
603
+ * protected readonly rawValue = transformedValue(this.value, {
604
+ * parse: (val) => {
605
+ * if (val === '') return {value: null};
606
+ * const num = Number(val);
607
+ * if (Number.isNaN(num)) {
608
+ * return {errors: [{kind: 'parse', message: `${val} is not numeric`}]};
609
+ * }
610
+ * return {value: num};
611
+ * },
612
+ * format: (val) => val?.toString() ?? '',
613
+ * });
614
+ * }
615
+ * ```
616
+ */
617
+ declare function transformedValue<TValue, TRaw>(value: ModelSignal<TValue>, options: TransformedValueOptions<TValue, TRaw>): TransformedValueSignal<TRaw>;
618
+
619
+ /**
620
+ * A directive that binds a `FieldTree` to a `<form>` element.
621
+ *
622
+ * It automatically:
623
+ * 1. Sets `novalidate` on the form element to disable browser validation.
624
+ * 2. Listens for the `submit` event, prevents the default behavior, and calls `submit()` on the
625
+ * `FieldTree`.
626
+ *
627
+ * @usageNotes
628
+ *
629
+ * ```html
630
+ * <form [formRoot]="myFieldTree">
631
+ * ...
632
+ * </form>
633
+ * ```
634
+ *
635
+ * @publicApi
636
+ * @experimental 21.0.0
637
+ */
638
+ declare class FormRoot<T> {
639
+ readonly fieldTree: i0.InputSignal<FieldTree<T>>;
640
+ protected onSubmit(event: Event): void;
641
+ static ɵfac: i0.ɵɵFactoryDeclaration<FormRoot<any>, never>;
642
+ static ɵdir: i0.ɵɵDirectiveDeclaration<FormRoot<any>, "form[formRoot]", never, { "fieldTree": { "alias": "formRoot"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
643
+ }
644
+
645
+ export { Debouncer, DisabledReason, FieldContext, FieldTree, FieldValidator, FormRoot, LogicFn, OneOrMany, PathKind, SchemaPath, SchemaPathRules, TreeValidationResult, TreeValidator, ValidationError, WithOptionalFieldTree, debounce, disabled, email, hidden, max, maxLength, min, minLength, pattern, readonly, required, transformedValue, validate, validateAsync, validateHttp, validateTree };
646
+ export type { AsyncValidatorOptions, FormCheckboxControl, FormUiControl, FormValueControl, HttpValidatorOptions, MapToErrorsFn, TransformedValueOptions, TransformedValueSignal };