Types

FieldState


FieldState

FieldState is an object containing the following values. Depending on your subscription when calling form.registerField(), some of the values may not be present.

active

boolean

Whether or not the field currently has focus.

blur

() => void

A function to blur the field (mark it as inactive).

change

(value: any) => void

A function to change the value of the field.

data

Object

A place for arbitrary values to be placed by mutators.

dirty

boolean

true when the value of the field is not equal to the initial value (using the isEqual comparator provided at field registration), false if the values are equal.

dirtySinceLastSubmit

boolean

true when the value of the field is not equal to the value last submitted (using the isEqual comparator provided at field registration), false if the values are equal.

error

any

The current validation error for this field.

focus

() => void

A function to focus the field (mark it as active).

initial

any

The initial value of the field. undefined if it was never initialized.

invalid

boolean

true if the field has a validation error or a submission error. false otherwise.

length

number

The length of the array if the value is an array. undefined otherwise.

modified

boolean

true if this field's value has ever been changed. false otherwise.

Once true, it will remain true for the lifetime of the field, or until the form or field state is reset.

modifiedSinceLastSubmit

boolean

true if this field's value has ever been changed since the last submission. false otherwise.

Once true, it will remain true until the next submit action, or until the form or field state is reset.

name

string

The name of the field.

pristine

boolean

true if the current value is === to the initial value, false if the values are !==.

submitError

any

The submission error for this field.

submitFailed

boolean

true if a form submission has been tried and failed. false otherwise.

submitSucceeded

boolean

true if the form has been successfully submitted. false otherwise.

submitting

boolean

true if the form is currently being submitted asynchronously. false otherwise.

touched

boolean

true if this field has ever gained and lost focus. false otherwise.

Useful for knowing when to display error messages.

valid

boolean

true if this field has no validation or submission errors. false otherwise.

validating

boolean

true if this field is currently waiting on its asynchronous field-level validation function to resolve. false otherwise.

value

any

The value of the field.

visited

boolean

true if this field has ever gained focus. false otherwise.