getValues() retrieves old value for hidden inputs with default value
See original GitHub issueDescribe the bug
I have a field array with a hidden input that is modified with setValue()
. If I later call getValues()
on that hidden input, I always get back the original value rather than the updated value. This is in spite of the watch API returning the updated value. This only occurs for hidden inputs; if I make it a text input, getValues()
returns the correct value.
To Reproduce
- Go to https://codesandbox.io/s/react-hook-form-field-array-hidden-input-vbn5w
- Open the console
- Click on “Modify x” next to the hidden field
- Observe that the watched value for
x
changes from “a” to “b” - Click on “Log x” next to the hidden field
- Observe that the logged value is “a”
- Repeat the above steps for the text input
- Observe that the logged value is now “b,” as expected
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-field-array-hidden-input-vbn5w
Expected behavior
I expect getValues()
to return the updated value as it does for text inputs.
Desktop (please complete the following information):
- OS: macOS 10.15.7
- Browser: Chrome
- Version: 86
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
DefaultValues of react-hook-form is not setting the values to ...
All the input fields are still empty. I want to have some default values in the input field of my form. reactjs ·...
Read more >HTML | DOM Input Hidden defaultValue Property
It returns the defaultValue property. hiddenObject.defaultValue. It is used to set the defaultValue property. hiddenObject.defaultValue = value.
Read more >3.1 - JavaScript Functions and Methods - ProcessMaker Wiki
The getValue() method returns the value of an input field in a Dynaform. $("#id").getValue(). Return Value The value returned by this function depends...
Read more >Google Visualization API Reference | Charts
If you change values in a DataTable after it is passed into a visualization's draw() method, the changes will not immediately change the...
Read more >ExcelScript.Range interface - Office Scripts | Microsoft Learn
Value is null when some columns in a range are hidden and other columns in the same range are not hidden. getColumnIndex(). Specifies...
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
I don’t think there is much we can do at this lib level 😦 and probably not going to hack to get it working as well. so please consider using CSS display none for the fix.
another quick solution here with Controller: https://codesandbox.io/s/react-hook-form-hidden-input-defaultvalue-forked-5wwmo?file=/src/index.js