🚀 Features
💣 Breaking Changes
- Change form state
isValid
, isTouched
, isDirty
to be methods instead, these methods now accept a path to narrow down which path of the form to return the state for. by @genu #126
useForm
's getErrors
now return an array of strings rather than Issue collection objects by @genu #126
const { isTouched, setTouched, isDirty, isValid, getErrors, getError, setErrors } = useForm();
// Check if the form is touched
isTouched();
// Check if a field/path is touched
isTouched('field');
isTouched('address.city');
// Set the touched state of the form
setTouched(true);
// Set the touched state of a field/path
setTouched('field', true);
setTouched('address.city', true);
// Check if the form is dirty
isDirty();
// Check if a field/path is dirty
isDirty('field');
isDirty('address.city');
// Check if the form is valid
isValid();
// Check if a field/path is valid
isValid('field');
isValid('address.city');
// Get all the errors for the form
getErrors(); // string[]
// Get the errors for a field/path
getErrors('field'); // string[]
getErrors('address.city'); // string[]
// Set the errors for a field/path
setErrors('field', 'This is an error');
setErrors('address.city', 'This is another error');
setErrors('address.city', ['This is another error', 'This is another error 2']);
// Gets the first error for a field/path
getError('field'); // string
getError('address.city'); // string
🐞 Bug Fixes