Skip to main content

Field

The Field class represents a single form field with its value, validation state, and metadata. Fields are created automatically by FormModel — you interact with them through model.fields.fieldName.

Properties

Value & State

PropertyTypeDescription
valueT | undefinedCurrent field value
namestringName of the field
dirtybooleantrue if value differs from initial value
interactedbooleantrue if a value has been set on this field
blurredbooleantrue if the field has been blurred at least once
hasValuebooleantrue if the field has a non-empty value
disabledbooleantrue if the field is disabled
requiredbooleantrue if required (always false when disabled)

Validation

PropertyTypeDescription
validbooleantrue if no error message is set
errorstring | undefinedCurrent validation error message
errorMessagestring | undefinedSame as error
validatingbooleantrue if an async validation is in progress
validatedAtLeastOncebooleantrue if validation has been run at least once
autoValidatebooleanWhether validation triggers automatically on value change
waitForBlurbooleanWhether validation is deferred until first blur

Other

PropertyTypeDescription
metaRecord<string, any> | undefinedArbitrary metadata from the descriptor
modelFormModel<K>Reference to the parent form model
rawErrorErrorLike | undefinedThe raw error object (with message property)

Methods

setValue(value?, opts?)

setValue(value?: T, opts?: {
resetInteractedFlag?: boolean;
commit?: boolean;
}): void

Set the field's value. By default, marks the field as interacted and triggers auto-validation if enabled.

form.fields.name.setValue('John');

// Programmatic update without marking as interacted
form.fields.name.setValue('Default', { resetInteractedFlag: true });

// Set and commit (new initial value)
form.fields.name.setValue('John', { commit: true });

validate(opts?)

validate(opts?: { force?: boolean }): Promise<void>

Run validation on this field. With force: true, validation runs regardless of interaction or blur state.

await form.fields.email.validate();
await form.fields.email.validate({ force: true });

markBlurredAndValidate()

markBlurredAndValidate(): void

Marks the field as blurred and triggers validation. Use this in onBlur handlers:

<input onBlur={() => field.markBlurredAndValidate()} />

restoreInitialValue(opts?)

restoreInitialValue(opts?: {
resetInteractedFlag?: boolean; // default: true
commit?: boolean; // default: true
}): void

Reverts the field to its last committed initial value.

commit()

commit(): void

Sets the current value as the new initial value, resetting dirty to false.

setDisabled(disabled)

setDisabled(disabled: boolean): void

Enable or disable the field. Disabling also clears any errors.

setRequired(val)

setRequired(val: boolean | string): void

Dynamically change the required state. Pass a string to set a custom error message.

setErrorMessage(msg?)

setErrorMessage(msg?: string): void

Manually set or clear the error message.

setError(error)

setError(error: { message: string }): void

Set the raw error object.

resetError()

resetError(): void

Clear the validation error.

clearValidation()

clearValidation(): void

Alias for resetError().

markAsInteracted()

markAsInteracted(): void

Manually mark the field as interacted.

resetInteractedFlag()

resetInteractedFlag(): void

Reset the interacted flag to false.

resetValidatedOnce()

resetValidatedOnce(): void

Reset the validatedAtLeastOnce flag to false.


Value Setter (property)

You can also set the value directly as a property:

form.fields.name.value = 'John';

This is equivalent to setValue('John') — it marks the field as interacted and triggers auto-validation.