Controller wrapped component does not update validation rules
See original GitHub issueDescribe 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:
- Wrap a component library’s Input element with
<Controller />
- Give it a rule that depends on a boolean state, when state is true, set rule to required, vice versa
- toggle the boolean state, the validation is not updated(
clearError
wouldn’t clear the existing error either)
Codesandbox link (Required)
- works ok with native form elements: https://codesandbox.io/s/react-hook-form-get-started-4ywl5?file=/src/index.js:758-884
- Not working with Controller component: https://codesandbox.io/s/react-hook-form-custom-input-c9uoz?file=/src/index.js
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:
- Created 3 years ago
- Reactions:1
- Comments:18 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s a CSB with an example of using @hookform/resovers with the Zod’s validation schema @edediostoosa
Thanks so much for the replies so far! I’ll checkout schema based validation 😃