-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isValid is sometimes false despite no errors #2755
Comments
Thanks @krnlde which version are you running? |
Latest, I can go back to the point where it worked and give the version. |
would be great if you can have a codesandbox for me, no stress if you are busy. i will take a look at it over the weekend. |
Alright! I'll try to do a reproducable codesandbox :) |
Here's a simple variant with only 2 radios where And here's a variant where the fields are required. The It seems the problem is with radios. I also use radios in my usecase where it breaks. |
looks like this is not a new issue, i switched to 6.4.1. it has the same behavior. |
also, both example doesn't have |
Hey! I have that for a while now, but it got worse somewhere between 6.4 and 6.6. I'm not sure right now which mode I'm using, but I assume onChange. |
oh, I see, so 6.4 prior is working? I will check it out. I could be related to bug fix. |
Unfortunately I didn't recognize exactly when it started to happen... When I'm back on my PC I can "time travel" and investigate |
Don't worry about it @krnlde leave it to you, i will let you know. |
https://codesandbox.io/s/rhf-isvalid-initially-false-bug-forked-sjifc?file=/src/App.tsx switched on mode: 'onChange' isValid is working for me. I think those two CSB is not reproducing the issue. |
I may need your help with a reproducible CSB. 🙏 |
Will do! Thank you :) Regarding not having the mode set to onChange: Shouldn't it be |
both codesandboxs are returning true after i attached |
Here I got the exact problem I have. It's a bit tricky to force the |
Thanks very much, @krnlde 👍 I will take a look at it tmr night. |
This issue is related to |
by the way, please read this: https://twitter.com/bluebill1049/status/1300231640392716288 just be careful with disabled input for submission. we are following the HTML standard in this lib. |
I've faced the same issue regarding https://codesandbox.io/s/react-hook-form-issue-2755-r5j7k Reproducible in following versions of
|
https://react-hook-form.com/api/useform/formstate
|
I am running into this issue too. It works with Destructuring |
for me it is not that the functionality does not work, it is the tests that are failing when using "isValid" in the check. |
Having similar issue now was there any solution |
hack until this is fixed. we can assert form validity by not having errors.
for initial validation failure
|
Having this issue on |
could you share a simple codesandox? |
@bluebill1049 as you can see initially |
That's expected @GProst errors state only start to update once user start to interact with the input/form, while isValid report the entire form valid state. |
@bluebill1049 ahh, sorry for false alarm then |
No worriees, @GProst if you want to force the errors state to be updated/rendered, you can try to call |
Putting |
Yes, this is the recommended way to validate |
@bluebill1049 Sorry to spam a closed ticket, but since it has some activity. RFC: How's the new |
call trigger() sort of works, but at the same time it checks all the other fields and resulted in error messages for all the other fields that user hasn't enter anything yet. What to do? Any expectation when this issue can be fixed? |
You can pass the field name / list of names to the |
Hi @soulbeing If you want re-validate or validate form without display errors, you can do this : const {trigger,clearErrors,} = useForm<FormData>({
resolver: yupResolver(...),
});
...
trigger(...).then(() => clearErrors()); |
Just another data point for analysis, I have this error when using autocomplete from my browser in an input field. When I type, no issues. When I just select the suggested option, no errors and |
How did you fix it? |
I ended up refactoring my form so I didn't need to use the isValid api. Now it goes through the normal check procedure on submit. I know that's not very helpful, but it's what worked for me. |
I now realised that I have a big Yup validation scheme and in my stepper From only few are being analysed. This is why the Form is !isValid. |
Why is this closed when the issue still exists? |
Using workaround of lodash isEmpty function: |
@bluebill1049 being confused about this as well, I just watched your video on formState. I've noticed that here in the video, an older version of the docs is showing, which is giving a crucial hint about
Why has this been removed from the docs? My impression is, this is still the case, and documenting it might be super helpful, as shown by the activity in this issue. If you agree, I'll add it back in. |
@stefanpl This has been improved: https://github.com/react-hook-form/react-hook-form/releases/tag/v7.39.0 |
I think you should wait for the next render to flush out the updated |
In the end using Here's my issue: instantiation of the form
Validation function
And is called by
In the first click in the button it prints "Error in the form" and in the second time it performs the request successfully. Both times the object printed by |
So the fix for me was reading
|
Describe the bug
I sometimes get
isValid = false
despite having no visible errors anderrors
object being an empty object ({}
)To Reproduce
I do not yet have a reproducable sandbox, but I already found a code piece that might be the problem. Please see additional context
Expected behavior
isValid should always reflect what the
errors
object contains (e.g.isValid = Object.keys(errors).length === 0
)Desktop (please complete the following information):
Additional context
The problematic line could be this code piece here:
react-hook-form/src/useForm.ts
Line 341 in 03216ed
isValid
parameter as the 4th parameter. Hence this linereact-hook-form/src/useForm.ts
Line 218 in 03216ed
!!isValid
which essentially means!!undefined === false
.AFAIK the problem only appears on async filled inputs (inputs that get their value via an api request).
The text was updated successfully, but these errors were encountered: