react-hook-form: Errors doesn't clear on change while using `onBlur` mode
Describe the bug
I’m not sure if this is a bug. But while using onBlur mode, errors don’t clear when a field is changed like they do while using onSubmit mode.
To Reproduce Here is a recreation.
Expected behavior I expect the errors to be cleared when the corresponding field changes.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 20 (18 by maintainers)
Commits related to this issue
- close #266 for revalidate with onChange — committed to react-hook-form/react-hook-form by bluebill1049 5 years ago
I think @Tymek 's right - if you have an error and you correct it (regardless of mode), the error should clear on the change, so you know it happened… I’d like to hear a scenario where that would be unwanted.
you want to use mode:
onTouched, reVliadateMode is for after submitHey @bluebill1049, thanks to you and everyone else for this awesome library.
I mentioned this on #283, but I figured it applied more here.
How can I 1) show an error
onBlur, and 2) clear an erroronChange?I tried this:
useForm({ mode: 'onBlur', reValidateMode: 'onChange' })This is great for showing an error on blur, but it also only clears the error on blur, not on change. Is there something wrong with that implementation?
Code sample here: https://codesandbox.io/s/react-hook-form-get-started-forked-vkk9j?file=/src/index.js:0-748
correct @barrymay, only for reValidate 😃
to be clear that would still avoid validating prior to the first submit if it’s onSubmit?
Yeah I think that would work
@barrymay @Tymek thanks guys, what about we make
revalidatetoonChange(any mode)? (then it’s not a breaking change and less code)Adding validation events is OK, but changing/overriding validation event might be a bad pattern. In my work as codebase grow I’d probably end up with many events that are created and cancelled in unpredictable way. Also,
modes are not mutually exclusive.Is something like this use case possible? Validation/revalidation events created in
useFormcannot be prevented, but are optional.I need some time to dive into code and make more educated guess.