react-hook-form: [Bug] Hidden input is ignored, when another input with `register()` is present

Hidden input is ignored, when another input with register() is present 🐞

To Reproduce

  1. Go to https://codesandbox.io/s/distracted-payne-1ooyh?file=/src/App.js
  2. Click on Submit
  3. Expected: In console check a submit object: test[0].validation has to be present with value false. Current: validation field is missing.
  4. Select any value in <select> dropdown
  5. Expected: In console check a watch object: test[0].validation has to be present with value true. Current: validation field is missing.

Codesandbox link https://codesandbox.io/s/distracted-payne-1ooyh?file=/src/App.js

  • Version: checked 6.5.3 and 6.6.0

Additional context Removing from code

<input
     defaultValue={fields[index].required}
     ref={register()}
     name={`test[${index}].required`}
     type="text"
/>

helps to solve onChange issue. But a default value is still ignored and empty.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 32 (17 by maintainers)

Most upvoted comments

Brilliant. Waiting for the next release! Thank you a lot!

please confirm if the above works. 👍

hmmm, looks like test again looks like it’s otherwise… I will take a look at it again later.

I guess remove(index) doesn’t remove items that were set with setValue. Sorry for disturbing you with this issue 😃

Nah, that’s fine. as long as we can resolve the problem here. The video certainly helped, but it should remove item even with setValue which is registered.

for min length, i think it’s easier to do the following:

useEffect(() => {
  if (!fields.length) {
    setError('xxx')
  }
})