December 2019
Intermediate to advanced
598 pages
12h 21m
English
We are going to execute validation rules when the field editor loses focus by carrying out the following steps:
const { setValue, touched, validate } = useContext( FormContext,);const handleChange = ( e: ChangeEvent<HTMLInputElement> | ChangeEvent<HTMLTextAreaElement>) => { if (setValue) { setValue(name, e.currentTarget.value); } if (touched[name]) { if (validate) { validate(name); } }};
So, we only invoke validation if the field has been touched.
Read now
Unlock full access