question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is Valid is not turning to false if you settled an error imperatively

See original GitHub issue

Describe the bug

isValid attribute is not changing if you set an error imperatively if you previosly set a defaultSchema using yup.

Scenario: Created a form instance using useForm hook, following the requirements of this particular edge case:

  • first name is required
  • if a question is provided then an answer has to be provided
  • if an answer is provided then a question has to be provided

To Reproduce

  1. type something in the first name;

  2. observe that the button that was disabled now it is enabled;

  3. type an answer;

  4. observe that the question has an error

Expected behavior isValid should be false, hence the button has to be disabled due to the errors object contains some errors in it.

Actual behavior isValid stays true, hence the button has to be enabled even though the error object contains some invalid fields to be validated.

Screenshots

Screen Shot 2020-05-22 at 3 50 28 PM Screen Shot 2020-05-22 at 3 50 36 PM Screen Shot 2020-05-22 at 3 50 46 PM

Desktop (please complete the following information):

  • OS: [iOS]
  • Browser [chrome]
  • Version [83.0.4103.61 (Official Build) (64-bit)]

Codesandbox link (Required) https://codesandbox.io/s/spring-pond-85dgq?file=/src/App.js

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bluebill1049commented, May 23, 2020

React Hook Form’s formstate isValid is driven by schema against form data (when not using the build-in validation). So setError is not going to be the solution, and we can’t make it work against validation schema result, because it will conflict the source of the truth.

Since schema validation isValid is going to drive by schema result (or kind has to), at the same time I see your concern as well when an error is not associated with the form. a situation like this I can’t see any other workaround than calling triggerValdiation() to validate the entire form and manage errors message manually via dirty & touched formState, or you will have to use resolver to write some custom logic.

I hope the above gives you some more insight.

1reaction
erickbelfycommented, May 23, 2020

But you’re right, i guess that can handle some edge cases using validationResolver instead of validationSchema, i will try to migrate it and see how it works

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - 'isValid' is always false
The loop is occurring when isValid is true , but stops when it is false . You can try it out here.
Read more >
Documentation
If the expression evaluates to true the event will trigger, otherwise it will not. Here is an example that triggers only on a...
Read more >
Declarative Validation - software is fun
If there are no errors, the provided input is valid, otherwise it isn't. We can wrap the result our validation returns in an...
Read more >
Discrepancy and Error in Radiology: Concepts, Causes and ...
The interpretation of a radiologic study is not a binary process; ... The courts occasionally treat false negative errors as if they were...
Read more >
Commercial Driver License Manual
you may present a valid or expired North Carolina photo Driver's. License, Learner's Permit, or Identification Card. If you do not have any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found