easy-forms
Validation

Messages & modes

Customize error messages and control when validation runs.

Custom messages

Every built-in rule accepts either a bare value or a { value, message } object:

validators: {
	required: { value: true, message: 'We need your name' },
	minLength: { value: 2, message: 'That seems too short' },
	pattern: { value: /^[A-Z]/, message: 'Start with a capital letter' },
}

Without a custom message, a sensible default is used.

Validation modes

The validation mode controls when a field validates:

PropTypeDefaultDescription
'onChange'modeValidate on every change. Most immediate feedback.
'onBlur'modeValidate when the field loses focus.
'onSubmit'modeValidate only when the form is submitted.
'all'modeValidate on both change and blur.

Regardless of mode, all visible fields are validated on submit before onSubmit runs.

The submit gate

The default footer keeps the submit button disabled until the form is dirty and valid, and disables it while submitting. You can build your own footer using useFormState if you need different behavior.