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` & `control` should not be triggered validation when its removed from the dom (Version 7)

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
bluebill1049commented, Apr 16, 2021

We are working on a feature for this.

0reactions
bluebill1049commented, May 21, 2021

you are right @fauzymk defaultValues will be registered for absent input. This is an improvement so users doesn’t have to register inputs manually at useEffect.

Screen Shot 2021-05-21 at 7 18 26 pm
Read more comments on GitHub >

github_iconTop 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 >

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