-
We have set the following validation strategy on our forms:
This tells the form: Only validate fields after they've been changed and the form has been tried to be submitted. Let's assume the user did not submit the form yet, but we use Would it make sense to build this logic into Some dummy code: const mode = 'onSubmit';
const reValidateMode = 'onChange';
const form = useForm({
mode,
reValidateMode,
});
const setValue = (name, value, options) => {
let shouldValidate;
if (mode === 'onSubmit' && reValidateMode === 'onChange') {
shouldValidate = form.formState.isSubmitted;
}
form.setValue(name, value, {
shouldValidate,
...options,
});
};
const trigger = (name, options = {}) => {
const { force } = options;
if (!force && mode === 'onSubmit' && !form.formState.isSubmitted) {
return;
}
form.trigger(name, options);
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Duplicate #9351 |
Beta Was this translation helpful? Give feedback.
Duplicate #9351