`Controller` & `control` should not be triggered validation when its removed from the dom (Version 7)
See original GitHub issueDescribe the bug The controller & control validate the fields that has been removed from the dom based on watching select value.
To Reproduce Steps to reproduce the behavior:
{watchBusinessOwnerForm("idType") === "PASSPORT" && (
<div class="flex items-start justify-between space-x-6">
<Controller
control={controlBusinessOwnerForm}
rules={{ required: "This field is required" }}
name="beginDate"
defaultValue=""
render={({
field: { ref, ...props },
fieldState: { invalid, error },
}) => (
<TextField
{...props}
type="date"
InputLabelProps={{
shrink: true,
}}
inputRef={ref}
error={invalid}
helperText={invalid ? error.message : ""}
className="w-full"
label="Passport date of issue"
/>
)}
/>
<Controller
control={controlBusinessOwnerForm}
rules={{ required: "This field is required" }}
name="endDate"
defaultValue=""
render={({
field: { ref, ...props },
fieldState: { invalid, error },
}) => (
<TextField
{...props}
type="date"
InputLabelProps={{
shrink: true,
}}
inputRef={ref}
error={invalid}
helperText={invalid ? error.message : ""}
className="w-full"
label="Passport date of expiry"
/>
)}
/>
</div>
)}
Codesandbox link (Required) Include a codesandbox will help us to investigate the issue quicker.
Expected behavior Its should not validate those fields that has been removed from the dom, its should work as v6. After the field add back only will be trigger the validation rules.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Migrate From V6 to V7 - Simple React forms validation
Important: input value and reference will no longer get removed after unmount unless shouldUnregister is true.
Read more >React Hook Form: A guide with examples - LogRocket Blog
Learn all about using forms in React with React Hook Form, including how to create and validate forms — even with third-party components....
Read more >Uncontrolled Components - React
In a controlled component, form data is handled by a React component. The alternative is uncontrolled components, where form data is handled by...
Read more >Client-side form validation - Learn web development | MDN
However, client-side validation should not be considered an exhaustive security measure! Your apps should always perform security checks on ...
Read more >angular - Reactive forms - disabled attribute - Stack Overflow
It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true when you set up...
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

We are working on a feature for this.
you are right @fauzymk
defaultValueswill be registered for absent input. This is an improvement so users doesn’t have to register inputs manually atuseEffect.