FieldState
A writable view of a FieldTree's state.
API
interface FieldState<TValue, TKey extends string | number = string | number> extends ReadonlyFieldState<TValue, TKey> {
readonly fieldTree: FieldTree<unknown, TKey, "writable">;
readonly value: WritableSignal<TValue>;
readonly controlValue: WritableSignal<TValue>;
markAsDirty(): void;
markAsTouched(options?: MarkAsTouchedOptions | undefined): void;
getError<K extends NgValidationError['kind']>(kind: K): ((Extract<RequiredValidationError, { kind: K; }> | Extract<MinValidationError, { kind: K; }> | Extract<MinDateValidationError, { kind: K; }> | Extract<MaxValidationError, { kind: K; }> | Extract<MaxDateValidationError, { kind: K; }> | Extract<MinLengthValidationError, { kind: K; }> | Extract<MaxLengthValidationError, { kind: K; }> | Extract<PatternValidationError, { kind: K; }> | Extract<EmailValidationError, { kind: K; }> | Extract<StandardSchemaValidationError, { kind: K; }> | Extract<NativeInputParseError, { kind: K; }>) & WithFieldTree) | undefined;
getError(kind: string): WithFieldTree | undefined;
reset(value?: TValue | undefined): void;
reloadValidation(): void;
readonly override disabled: Signal<boolean>;
readonly override max: Signal<NonNullable<TValue> | undefined> | undefined;
readonly override maxLength: Signal<number | undefined> | undefined;
readonly override min: Signal<NonNullable<TValue> | undefined> | undefined;
readonly override minLength: Signal<number | undefined> | undefined;
readonly override name: Signal<string>;
readonly override pattern: Signal<readonly RegExp[]>;
readonly override readonly: Signal<boolean>;
readonly override required: Signal<boolean>;
readonly override touched: Signal<boolean>;
readonly override dirty: Signal<boolean>;
readonly override hidden: Signal<boolean>;
readonly override disabledReasons: Signal<readonly DisabledReason[]>;
readonly override errors: Signal<WithFieldTree[]>;
readonly override errorSummary: Signal<WithFieldTree[]>;
readonly override valid: Signal<boolean>;
readonly override invalid: Signal<boolean>;
readonly override pending: Signal<boolean>;
readonly override submitting: Signal<boolean>;
readonly override keyInParent: Signal<TKey>;
readonly override formFieldBindings: Signal<readonly FormFieldBinding[]>;
override metadata<M>(key: MetadataKey<M, any, any>): M | undefined;
override hasMetadata(key: MetadataKey<any, any, any>): boolean;
override focusBoundControl(options?: FocusOptions | undefined): void;
}
value
WritableSignal<TValue>A writable signal containing the value for this field.
Updating this signal will update the data model that the field is bound to.
While updates from the UI control are eventually reflected here, they may be delayed if debounced.
controlValue
WritableSignal<TValue>A signal containing the value of the control to which this field is bound.
This differs from value in that it's not subject to debouncing, and thus is used to buffer debounced updates from the control to the field. This will also not take into account the controlValue of children.
markAsDirty
voidSets the dirty status of the field to true.
void
markAsTouched
voidSets the touched status of the field and its descendants to true.
void
getError
((Extract<RequiredValidationError, { kind: K; }> | Extract<MinValidationError, { kind: K; }> | Extract<MinDateValidationError, { kind: K; }> | Extract<MaxValidationError, { kind: K; }> | Extract<MaxDateValidationError, { kind: K; }> | Extract<MinLengthValidationError, { kind: K; }> | Extract<MaxLengthValidationError, { kind: K; }> | Extract<PatternValidationError, { kind: K; }> | Extract<EmailValidationError, { kind: K; }> | Extract<StandardSchemaValidationError, { kind: K; }> | Extract<NativeInputParseError, { kind: K; }>) & WithFieldTree) | undefinedGets the first validation error of the given kind on this field.
This method is reactive and will re-evaluate when the field's errors change if called within a reactive context (e.g. computed or effect).
KThe kind of error (e.g. 'required', 'min').
((Extract<RequiredValidationError, { kind: K; }> | Extract<MinValidationError, { kind: K; }> | Extract<MinDateValidationError, { kind: K; }> | Extract<MaxValidationError, { kind: K; }> | Extract<MaxDateValidationError, { kind: K; }> | Extract<MinLengthValidationError, { kind: K; }> | Extract<MaxLengthValidationError, { kind: K; }> | Extract<PatternValidationError, { kind: K; }> | Extract<EmailValidationError, { kind: K; }> | Extract<StandardSchemaValidationError, { kind: K; }> | Extract<NativeInputParseError, { kind: K; }>) & WithFieldTree) | undefinedThe first matching error, or undefined if none.
getError
WithFieldTree | undefinedstring
WithFieldTree | undefined
reset
voidreloadValidation
voidReloads all asynchronous validators for this field and its descendants.
void
disabled
Signal<boolean>A signal indicating whether the field is currently disabled.
max
Signal<NonNullable<TValue> | undefined> | undefinedA signal indicating the field's maximum value, if applicable.
Applies to <input> with a numeric or date type attribute and custom controls.
maxLength
Signal<number | undefined> | undefinedA signal indicating the field's maximum string length, if applicable.
Applies to <input>, <textarea>, and custom controls.
min
Signal<NonNullable<TValue> | undefined> | undefinedA signal indicating the field's minimum value, if applicable.
Applies to <input> with a numeric or date type attribute and custom controls.
minLength
Signal<number | undefined> | undefinedA signal indicating the field's minimum string length, if applicable.
Applies to <input>, <textarea>, and custom controls.
name
Signal<string>A signal of a unique name for the field, by default based on the name of its parent field.
pattern
Signal<readonly RegExp[]>A signal indicating the patterns the field must match.
readonly
Signal<boolean>A signal indicating whether the field is currently readonly.
required
Signal<boolean>A signal indicating whether the field is required.
touched
Signal<boolean>A signal indicating whether the field has been touched by the user.
dirty
Signal<boolean>A signal indicating whether field value has been changed by user.
disabledReasons
Signal<readonly DisabledReason[]>errors
Signal<WithFieldTree[]>errorSummary
Signal<WithFieldTree[]>A signal containing the errors of the field and its descendants.
valid
Signal<boolean>A signal indicating whether the field's value is currently valid.
Note: valid() is not the same as !invalid().
-
valid()istruewhen there are no validation errors and no pending validators. -
invalid()istruewhen there are validation errors, regardless of pending validators.
Ex: consider the situation where a field has 3 validators, 2 of which have no errors and 1 of which is still pending. In this case valid() is false because of the pending validator. However invalid() is also false because there are no errors.
invalid
Signal<boolean>A signal indicating whether the field's value is currently invalid.
Note: invalid() is not the same as !valid().
-
invalid()istruewhen there are validation errors, regardless of pending validators. -
valid()istruewhen there are no validation errors and no pending validators.
Ex: consider the situation where a field has 3 validators, 2 of which have no errors and 1 of which is still pending. In this case invalid() is false because there are no errors. However valid() is also false because of the pending validator.
pending
Signal<boolean>Whether there are any validators still pending for this field.
submitting
Signal<boolean>A signal indicating whether the field is currently in the process of being submitted.
keyInParent
Signal<TKey>The property key in the parent field under which this field is stored. If the parent field is array-valued, for example, this is the index of this field in that array.
formFieldBindings
Signal<readonly FormFieldBinding[]>The FormField directives that bind this field to a UI control.
metadata
M | undefinedReads a metadata value from the field.
M | undefined
hasMetadata
booleanChecks whether a metadata value exists on the field.
boolean
focusBoundControl
voidFocuses the first UI control in the DOM that is bound to this field state. If no UI control is bound, does nothing.
FocusOptions | undefinedOptional focus options to pass to the native focus() method.
void
Super-powered by Google ©2010–2025.
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
https://angular.dev/api/forms/signals/FieldState