Black Lives Matter. Support Equal Justice.
Types

Config


Config

Config is an object containing the following values:

debug

(
  state: FormState,
  fieldStates: { [string]: FieldState }
) => void

Optional.

A callback for debugging that receives the form state and the states of all the fields. It's called on every state change. A typical thing to pass in might be console.log.

Related:

destroyOnUnregister

Optional.

boolean

If true, the value of a field will be destroyed when that field is unregistered. Defaults to false. Can be useful when creating dynamic forms where only form values displayed need be submitted.

initialValues

FormValues | Object

Optional.

The initial values of your form. These will also be used to compare against the current values to calculate pristine and dirty.

If you are using Typescript, these values must be the same type as the object given to your onSubmit function.

keepDirtyOnReinitialize

boolean

Optional.

If true, only pristine values will be overwritten when initialize(newValues) is called. This can be useful for allowing a user to continue to edit a record while the record is being saved asynchronously, and the form is reinitialized to the saved values when the save is successful. Defaults to false.

mutators

{ [string]: Mutator }

Optional.

Named Mutator functions.

onSubmit

(
  values: FormValues,
  form: FormApi,
  callback: ?(errors: ?Object) => void
) => ?Object | Promise<?Object> | void

Required.

Function to call when the form is submitted. There are three possible ways to write an onSubmit function:

1. Synchronous

Returns undefined on success, or an Object of submission errors on failure.

2. Asynchronous with a callback

Returns undefined, calls callback() with no arguments on success, or with an Object of submission errors on failure.

3. Asynchronous with a Promise

Returns a Promise<?Object> that resolves with no value on success or resolves with an Object of submission errors on failure. The reason it resolves with errors is to leave rejection for when there is a server or communications error.

Submission Errors

Submission errors must be in the same shape as the values of the form. You may return a generic error for the whole form (e.g. 'Login Failed') using the special FORM_ERROR string key.

Related:

validate

(values: FormValues) => Object | Promise<Object>

Optional.

A whole-record validation function that takes all the values of the form and returns any validation errors. There are two possible ways to write a validate function:

1. Synchronous

Returns {} or undefined when the values are valid, or an Object of validation errors when the values are invalid.

2. Asynchronous with a Promise

Returns a Promise<?Object> that resolves with no value on success or resolves with an Object of validation errors on failure. The reason it resolves with errors is to leave rejection for when there is a server or communications error.

Validation Errors

Validation errors must be in the same shape as the values of the form. You may return a generic error for the whole form using the special FORM_ERROR string key.

validateOnBlur

boolean

Optional.

If true, validation will happen on blur. If false, validation will happen on change. Defaults to false.