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.

Controller wrapped component does not update validation rules

See original GitHub issue

Describe the bug Native HTML elements work perfectly with dynamic validation rules (e.g. an input is required under mode A but not required under mode B), however when working with 3rd party libraries and Controller component, the rules do not get updated, it keeps using the original rule supplied to it for validation.

To Reproduce Steps to reproduce the behavior:

  1. Wrap a component library’s Input element with <Controller />
  2. Give it a rule that depends on a boolean state, when state is true, set rule to required, vice versa
  3. toggle the boolean state, the validation is not updated(clearError wouldn’t clear the existing error either)

Codesandbox link (Required)

Expected behavior After updating the validation rule, it should validate with the latest rule instead of the old one.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS 10.15
  • Browser Chrome 81
  • Version React-hook-form 5.5.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Moshyfawncommented, Feb 10, 2022

Here’s a CSB with an example of using @hookform/resovers with the Zod’s validation schema @edediostoosa

1reaction
LookRaincommented, May 6, 2020

Yes, if your validation logic is dynamic or you can look into schema validation.

Thanks so much for the replies so far! I’ll checkout schema based validation 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Controller | React Hook Form - Simple React forms validation
This wrapper component will make it easier for you to work with them. ... Validation rules in the same format for register options,...
Read more >
Show Error From Controllers in React Hook Forms
I am trying to throw required errors from my input which I have wrapped in a Controller component from react- ...
Read more >
React form validation solutions: An ultimate roundup
This roundup is a comprehensive look at some of the most popular solutions for form management and validation in React.
Read more >
The campingListItem JavaScript controller isn't setting the ...
Here is the code I'm using to set the item as packed... component.set("v.item.Packed__c", true ); I'm assuming the validator does not like ...
Read more >
Form | Quasar Framework
QInput, QSelect or QField wrapped components must use the internal validation (NOT the external one). If you want to take advantage of the...
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