Reset forces all fields to be changed
See original GitHub issueDescribe the bug
When using {mode: 'onChange'}
with validations, reset()
sets isValid
as false
but now it enforces all the fields to be changed to set isValid
as true
To Reproduce Steps to reproduce the behavior:
- Go to the sandbox below
- Notice that
isValid
istrue
- Click on
RESET
button (nowisValid
isfalse
) - Change just one input value
- Notice that
isValid
is stillfalse
- Click on
VALIDATE
or change the other input value (nowisValid
istrue
)
Codesandbox link https://codesandbox.io/s/react-hook-form-reset-forces-all-fields-to-be-changed-p9q8v
Expected behavior
After calling reset()
with default values we can do two different things:
- If default values fulfill form validations
isValid
should betrue
. - If default values fulfill form validations as soon as one input changes to a still valid value
isValid
should betrue
. If you agree that this is a bug decide which one of the above solutions is better and makes more sense.
Desktop (please complete the following information):
- OS: macOS Catalina Version 10.15.1
- Browser: Google Chrome Version 78.0.3904.108 (Official Build) (64-bit)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Force field to become blank based on another field's value
Then use this code in the OnChange property of Report type to conditionally reset the Published dropdown when the value selected is 'Data ......
Read more >useForm - reset - React Hook Form
Reset the entire form state, fields reference, and subscriptions. There are optional arguments and will allow partial form state reset.
Read more >Resetting a multi-stage form with jQuery - Stack Overflow
resetValue(); // reset all fields in a certain container $( "#someContainer :input" ).resetValue(); // reset all fields $( ":input" ).resetValue ...
Read more >How do I reset/restart an auto number field automatically?
I want to reset/restart an auto number field automatically every month. How do I reset/restart automatically? ... 3. Click "Change Field Type" and ......
Read more >After Displaying Alert on Field Change reset the checkbox
Created a check box: Display_Alert__c default 'False' · Created a Record Triggered Flow that checks for isChange(Field__c) and sets 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
@bluebill1049 please take a look again to the sandbox I updated it with your suggestions. And
isValid
is nottrue
until I executetriggerValidation
or I change all the inputs. Take into consideration that this happens only if you first executereset
https://codesandbox.io/s/react-hook-form-reset-forces-all-fields-to-be-changed-p9q8vthat’s fine @krnlde 😃