All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- [
useForm
] Fixed an issue where failed submissions would reset the form.
- [
useForm
] Fixed an issue that allowed submission with invalid forms.
- [
useForm
,useFields
] Change to values object type toany
.
- [
useForm
,useSubmission
] Fixed an issue with asynconSubmit
handlers that resulted in theonSubmit
function being called with empty values.
- [
useForm
]reset
function now supports an optionalevent: SyntheticEvent
parameter. This parameter is used to call.closest('form').reset()
on theevent.target
so that uncontrolled forms like those composed usinguseSettersAsRefEventHandler
are resetted. - [
useForm
]onSubmit
now resets uncontrolled forms. See comment above aboutreset
function.
- [
useForm
,useSubmission
] Both hooks now return asubmitFeedback
object that has anerror
ormessage
property. Theerror
property is set whenonSubmit
throws an error or returnsPromise.reject()
. Themessage
property is set after callingsetFeedback
. Only one of those properties can be set at the same time. Also note that throwing an error or returningPromise.reject()
aborts the form reset step. - [
useForm
,useSubmission
]onSubmit
now accepts avalues
object as the first parameter and anonSubmitModifiers
object as a new second argument.onSubmitModifiers
is an object that consist of asetError: (name: string, error: string) => void
function, asetFeedback: (feedback: string) => void
function, and the optionalevent: SyntheticEvent
event object.setError
will set an error value for the input with the specified name as well as prevent the form from resetting.setFeedback
will set themessage
property for thesubmitFeedback
value (see bullet above).event
is the event that was passed to thesubmit
function. - [
useSubmission
] Added three more props (reset
,setError
,values
) to help streamline the useSubmission hook.reset
is a function used to reset the form values after submission.setError
is a fucntion used to set an error for a sepecified form input.values
is an optional object map of the form values.
- [
useForm
,useValidation
] Fixed an issues with theerrors
types.
- [
useForm
,useTouch
] Adds a isDirty field that is set to true when any field is touched.
- [
useForm
] Fixed an issue whereonSubmit
was being called with the current values.
- [
useSubmission
]onSubmit
will be called with the current Event ifsubmit
is called with an event. - [
useForm
]onSubmit
the second argument will be the event ifsubmit
is called with an event.
- [
useValidation
] RemovedisValidating
from the hook. A hook to track if a function is currently being called will be added in a later update.
- Typescript definition files
- [
useSettersAsRefEventHandler
] The object api now supports amountedValues
property that is the shape of a value object map (eg{email: 'user@example.com'}
). When the ref callback is mounted on an element and themountedValues
property is set, then the specified element'svalue
property will be set to the correspondingmountedValues
property that shares the same name as the specified element's name propert (egelement.value = mountedValues[element.name]
). - [
useValidation
] the returned promise forvalidate
andvalidateByName
no longer resolves to a map of errors. - [
useSubmission
] Now accepts an optionaldisabled
flag that is used to prevent submission if the value istrue
. This hook also no longer accepts avalidator
that resolves to a map of errors. The preferred way of preventing submission is to set thedisabled
flag to true. Thevalidator
prop is now optional.
- [
useValidateAsSetter
] Added a hook that supports usingvalidate
fromuseFrom
withuseSettersAsRefEventHandler
, anduseSettersAsEventHandler
- [
useForm
] addsuseConstraints
support via the optionalconstraints
parameter
- [
useForm
] RenameddefaultValues
parameter toinitialValues
- [
useSettersAsRefEventHandler
]event
is optional when using the hook with options. - [
useSettersAsRefEventHandler
]handlers
must be called with an array of function when using the hook with options.
- [
useNormalizers
] added a hook (useNormalizers
) for normalizing input values - [
normalizeNestedObjects
] added auseNormalizer
compatible function that handles nested objects and arrays
- [
useSettersAsEventHandler
] Changed the third argument that is invoked with each handler from an Event to an EventTarget
- [
useForm
,useFields
] Resetting fields now sets the value to empty string if no default value
- [
useConstraint
] Update the number regex pattern
- [
useError
,useFields
,useTouch
] Added the ability to set values using a function callback
- [
useValidation
] Removed the unusedexpectedFields
parameter
- [
useValidation
] Preventsvalidate
from calling validators twice whenuseValidation
is called with a validation map.
- [
useConstraint
] Updated the url regex pattern - [
useConstraint
] Updated all constraints to accept0
as a non-empty value
- [
useConstraint
] Fixed an issue with setting custom error messages for required constraints