@angular/forms 21.2.0-next.2 → 21.2.0-rc.0
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 → _validation_errors-chunk.mjs} +86 -81
- package/fesm2022/_validation_errors-chunk.mjs.map +1 -0
- package/fesm2022/forms.mjs +170 -189
- package/fesm2022/forms.mjs.map +1 -1
- package/fesm2022/signals-compat.mjs +9 -11
- package/fesm2022/signals-compat.mjs.map +1 -1
- package/fesm2022/signals.mjs +1017 -858
- 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 +302 -262
- package/types/forms.d.ts +1 -1
- package/types/signals-compat.d.ts +1 -1
- package/types/signals.d.ts +119 -15
- package/fesm2022/_structure-chunk.mjs.map +0 -1
package/types/signals.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.2.0-
|
|
2
|
+
* @license Angular v21.2.0-rc.0
|
|
3
3
|
* (c) 2010-2026 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
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, Field, FieldState, FormField, FormFieldBindingOptions, FormOptions, FormSubmitOptions, IgnoreUnknownProperties, ItemFieldContext, ItemType, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MaybeFieldTree, MaybeSchemaPathTree, MetadataKey, MetadataReducer, MetadataSetterType, MinLengthValidationError, MinValidationError, NativeInputParseError, 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';
|
|
10
11
|
import { HttpResourceRequest, HttpResourceOptions } from '@angular/common/http';
|
|
11
12
|
import '@angular/forms';
|
|
12
13
|
import '@standard-schema/spec';
|
|
@@ -388,7 +389,7 @@ declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root
|
|
|
388
389
|
* @category control
|
|
389
390
|
* @experimental 21.0.0
|
|
390
391
|
*/
|
|
391
|
-
interface FormUiControl
|
|
392
|
+
interface FormUiControl {
|
|
392
393
|
/**
|
|
393
394
|
* An input to receive the errors for the field. If implemented, the `Field` directive will
|
|
394
395
|
* automatically bind errors from the bound field to this input.
|
|
@@ -469,12 +470,6 @@ interface FormUiControl<TValue> {
|
|
|
469
470
|
* will automatically bind the value patterns from the bound field to this input.
|
|
470
471
|
*/
|
|
471
472
|
readonly pattern?: InputSignal<readonly RegExp[]> | InputSignalWithTransform<readonly RegExp[], unknown>;
|
|
472
|
-
/**
|
|
473
|
-
* A signal containing the current parse errors for the control.
|
|
474
|
-
* This allows the control to communicate to the form that there are additional validation errors
|
|
475
|
-
* beyond those produced by the schema, due to being unable to parse the user's input.
|
|
476
|
-
*/
|
|
477
|
-
readonly parseErrors?: Signal<ValidationError.WithoutFieldTree[]>;
|
|
478
473
|
/**
|
|
479
474
|
* Focuses the UI control.
|
|
480
475
|
*
|
|
@@ -496,7 +491,7 @@ interface FormUiControl<TValue> {
|
|
|
496
491
|
* @category control
|
|
497
492
|
* @experimental 21.0.0
|
|
498
493
|
*/
|
|
499
|
-
interface FormValueControl<TValue> extends FormUiControl
|
|
494
|
+
interface FormValueControl<TValue> extends FormUiControl {
|
|
500
495
|
/**
|
|
501
496
|
* The value is the only required property in this contract. A component that wants to integrate
|
|
502
497
|
* with the `Field` directive via this contract, *must* provide a `model()` that will be kept in
|
|
@@ -520,7 +515,7 @@ interface FormValueControl<TValue> extends FormUiControl<TValue> {
|
|
|
520
515
|
* @category control
|
|
521
516
|
* @experimental 21.0.0
|
|
522
517
|
*/
|
|
523
|
-
interface FormCheckboxControl extends FormUiControl
|
|
518
|
+
interface FormCheckboxControl extends FormUiControl {
|
|
524
519
|
/**
|
|
525
520
|
* The checked is the only required property in this contract. A component that wants to integrate
|
|
526
521
|
* with the `Field` directive, *must* provide a `model()` that will be kept in sync with the
|
|
@@ -548,5 +543,114 @@ interface FormCheckboxControl extends FormUiControl<boolean> {
|
|
|
548
543
|
*/
|
|
549
544
|
declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, durationOrDebouncer: number | Debouncer<TValue, TPathKind>): void;
|
|
550
545
|
|
|
551
|
-
|
|
552
|
-
|
|
546
|
+
/**
|
|
547
|
+
* Result of parsing a raw value into a model value.
|
|
548
|
+
*/
|
|
549
|
+
interface ParseResult<TValue> {
|
|
550
|
+
/**
|
|
551
|
+
* The parsed value, if parsing was successful.
|
|
552
|
+
*/
|
|
553
|
+
readonly value?: TValue;
|
|
554
|
+
/**
|
|
555
|
+
* Errors encountered during parsing, if any.
|
|
556
|
+
*/
|
|
557
|
+
readonly errors?: readonly ValidationError.WithoutFieldTree[];
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Options for `transformedValue`.
|
|
561
|
+
*
|
|
562
|
+
* @experimental 21.2.0
|
|
563
|
+
*/
|
|
564
|
+
interface TransformedValueOptions<TValue, TRaw> {
|
|
565
|
+
/**
|
|
566
|
+
* Parse the raw value into the model value.
|
|
567
|
+
*
|
|
568
|
+
* Should return an object containing the parsed result, which may contain:
|
|
569
|
+
* - `value`: The parsed model value. If `undefined`, the model will not be updated.
|
|
570
|
+
* - `errors`: Any parse errors encountered. If `undefined`, no errors are reported.
|
|
571
|
+
*/
|
|
572
|
+
parse: (rawValue: TRaw) => ParseResult<TValue>;
|
|
573
|
+
/**
|
|
574
|
+
* Format the model value into the raw value.
|
|
575
|
+
*/
|
|
576
|
+
format: (value: TValue) => TRaw;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* A writable signal representing a "raw" UI value that is synchronized with a model signal
|
|
580
|
+
* via parse/format transformations.
|
|
581
|
+
*
|
|
582
|
+
* @category control
|
|
583
|
+
* @experimental 21.2.0
|
|
584
|
+
*/
|
|
585
|
+
interface TransformedValueSignal<TRaw> extends WritableSignal<TRaw> {
|
|
586
|
+
/**
|
|
587
|
+
* The current parse errors resulting from the last transformation.
|
|
588
|
+
*/
|
|
589
|
+
readonly parseErrors: Signal<readonly ValidationError.WithoutFieldTree[]>;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Creates a writable signal representing a "raw" UI value that is transformed to/from a model
|
|
593
|
+
* value via `parse` and `format` functions.
|
|
594
|
+
*
|
|
595
|
+
* This utility simplifies the creation of custom form controls that parse a user-facing value
|
|
596
|
+
* representation into an underlying model value. For example, a numeric input that displays and
|
|
597
|
+
* accepts string values but stores a number.
|
|
598
|
+
*
|
|
599
|
+
* @param value The model signal to synchronize with.
|
|
600
|
+
* @param options Configuration including `parse` and `format` functions.
|
|
601
|
+
* @returns A `TransformedValueSignal` representing the raw value with parse error tracking.
|
|
602
|
+
* @experimental 21.2.0
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```ts
|
|
606
|
+
* @Component({
|
|
607
|
+
* selector: 'number-input',
|
|
608
|
+
* template: `<input [value]="rawValue()" (input)="rawValue.set($event.target.value)" />`,
|
|
609
|
+
* })
|
|
610
|
+
* export class NumberInput implements FormValueControl<number | null> {
|
|
611
|
+
* readonly value = model.required<number | null>();
|
|
612
|
+
*
|
|
613
|
+
* protected readonly rawValue = transformedValue(this.value, {
|
|
614
|
+
* parse: (val) => {
|
|
615
|
+
* if (val === '') return {value: null};
|
|
616
|
+
* const num = Number(val);
|
|
617
|
+
* if (Number.isNaN(num)) {
|
|
618
|
+
* return {errors: [{kind: 'parse', message: `${val} is not numeric`}]};
|
|
619
|
+
* }
|
|
620
|
+
* return {value: num};
|
|
621
|
+
* },
|
|
622
|
+
* format: (val) => val?.toString() ?? '',
|
|
623
|
+
* });
|
|
624
|
+
* }
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
declare function transformedValue<TValue, TRaw>(value: ModelSignal<TValue>, options: TransformedValueOptions<TValue, TRaw>): TransformedValueSignal<TRaw>;
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* A directive that binds a `FieldTree` to a `<form>` element.
|
|
631
|
+
*
|
|
632
|
+
* It automatically:
|
|
633
|
+
* 1. Sets `novalidate` on the form element to disable browser validation.
|
|
634
|
+
* 2. Listens for the `submit` event, prevents the default behavior, and calls `submit()` on the
|
|
635
|
+
* `FieldTree`.
|
|
636
|
+
*
|
|
637
|
+
* @usageNotes
|
|
638
|
+
*
|
|
639
|
+
* ```html
|
|
640
|
+
* <form [formRoot]="myFieldTree">
|
|
641
|
+
* ...
|
|
642
|
+
* </form>
|
|
643
|
+
* ```
|
|
644
|
+
*
|
|
645
|
+
* @publicApi
|
|
646
|
+
* @experimental 21.0.0
|
|
647
|
+
*/
|
|
648
|
+
declare class FormRoot<T> {
|
|
649
|
+
readonly fieldTree: i0.InputSignal<FieldTree<T>>;
|
|
650
|
+
protected onSubmit(event: Event): void;
|
|
651
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FormRoot<any>, never>;
|
|
652
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<FormRoot<any>, "form[formRoot]", never, { "fieldTree": { "alias": "formRoot"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
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 };
|
|
656
|
+
export type { AsyncValidatorOptions, FormCheckboxControl, FormUiControl, FormValueControl, HttpValidatorOptions, MapToErrorsFn, ParseResult, TransformedValueOptions, TransformedValueSignal };
|