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.

getValues() retrieves old value for hidden inputs with default value

See original GitHub issue

Describe 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

  1. Go to https://codesandbox.io/s/react-hook-form-field-array-hidden-input-vbn5w
  2. Open the console
  3. Click on “Modify x” next to the hidden field
  4. Observe that the watched value for x changes from “a” to “b”
  5. Click on “Log x” next to the hidden field
  6. Observe that the logged value is “a”
  7. Repeat the above steps for the text input
  8. 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Nov 22, 2020

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.

0reactions
bluebill1049commented, Nov 22, 2020
Read more comments on GitHub >

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

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