react-custom-validation
react-custom-validation copied to clipboard
How/when to use initValidation?
Summary
I want to reset $validation
passed to my component that's wrapped by validated
. I tried calling initValidation
within validated
; however, that did not work. How/when do I call initValidation
so that I can reset the validation?
Details
I'm trying to implement the following UX:
- User visits page with form
- User fills out fields in form
- User submits form
- After form is submitted, the fields are cleared so they can resubmit the form with new/different data.
I have the validation in place as per the documentation and it is working; however, I'm trying to find a way to reset the properties on the $validation
prop so that the form doesn't appear to be invalid when their values are reset to their defaults via setState
Is the correct way to achieve this by calling initValidation()
? If so, when should this method be called? I've tried calling it in validated
. For example:
const validatedComponent = validated((props) => {
const { shouldReset } = props;
if(shouldReset) {
initValidation();
}
return {
fields: ['quantity'],
validations: [
[
(value) => value ? true : 'Required',
parentCompany,
startCase(viewModelKeyMap.parentCategory)
]
]
};
})(Component);
But this doesn't seem to work.