Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with clear array errors in FieldArray #1097

Closed
DisaPadla opened this issue Feb 25, 2020 · 17 comments · Fixed by #1111
Closed

issue with clear array errors in FieldArray #1097

DisaPadla opened this issue Feb 25, 2020 · 17 comments · Fixed by #1111
Labels
bug Something isn't working

Comments

@DisaPadla
Copy link

DisaPadla commented Feb 25, 2020

When "errors" is empty the array is not been removed in "errors" object

Steps to reproduce the behavior:

  1. remove value from the first input
  2. submit button should be disabled
  3. enter "10" to the first input
  4. submit button still disabled
  5. look at console.log(errors);. We still have an array in "errors" object

Expected behavior
submit button should be active

Codesandbox link
https://codesandbox.io/embed/react-hook-validate-trigger-sb1lj?fontsize=14&hidenavigation=1&theme=dark

discussion on spectrum
https://spectrum.chat/react-hook-form/help/strange-validation-behavior-for-fields-array~b6982a9b-25f3-4fc7-adf5-cd3e1f5a27f7

@bluebill1049 bluebill1049 changed the title Strange validation behavior for fields array issue with clear array errors in FieldArray Feb 25, 2020
@bluebill1049 bluebill1049 added the bug Something isn't working label Feb 25, 2020
@bluebill1049 bluebill1049 self-assigned this Feb 25, 2020
@bluebill1049
Copy link
Member

@DisaPadla
Copy link
Author

@bluebill1049
Copy link
Member

please help testing on 4.9.9-beta.2

@DisaPadla
Copy link
Author

@bluebill1049 I found only 4.9.9-beta.1 on codesandbox. I could test on my own project

@bluebill1049
Copy link
Member

bluebill1049 commented Feb 27, 2020

hey @DisaPadla you can install this beta on the CSB (ignore the drop down, just click install) :) make sure point to 'react-hook-form' instead of './src' folder.

@DisaPadla
Copy link
Author

@bluebill1049 look at this example
https://codesandbox.io/s/formstate-is-not-still-valid-after-removing-items-ycu19

  1. Append two items
  2. make "onBlur" for both new items
  3. Remove second and third items

Result
formState.isValid is still false. errors object contains test: [undefined]

@bluebill1049
Copy link
Member

aha awesome thanks!

@DisaPadla
Copy link
Author

I didn't find anything else.

@bluebill1049
Copy link
Member

Awesome thanks a lot, I will patch that issue tonight. ❤️

@bluebill1049
Copy link
Member

patched: https://codesandbox.io/s/formstate-is-not-still-valid-after-removing-items-ewufu making PR for the fix now :)

@DisaPadla
Copy link
Author

formState.isValid is still false. Is it okay?

@bluebill1049
Copy link
Member

u sure? works for me:
Screen Shot 2020-02-27 at 8 19 46 pm

https://codesandbox.io/s/formstate-is-not-still-valid-after-removing-items-ewufu

try again, maybe i forgot to save.

@DisaPadla
Copy link
Author

Oh, look at this case:

  1. Append a second item
  2. Append a third item
  3. Make onBlur for the second item
  4. Make onBlur for the third item
  5. Click on Delete for the SECOND item
  6. Click on Delete for the third item
    IsValid is false

But if you replace 5 and 6 steps, like
5. Click on Delete for the THIRD item
6. Click on Delete for the second item
all looks good

@bluebill1049
Copy link
Member

interesting... you are right

@bluebill1049
Copy link
Member

sorted :) https://codesandbox.io/s/formstate-is-not-still-valid-after-removing-items-ewufu thanks a lot for your testing effort.

@DisaPadla
Copy link
Author

looks good for me!

@bluebill1049
Copy link
Member

awesome! thanks for the verification.

bluebill1049 added a commit that referenced this issue Feb 28, 2020
* close #1097 issue with formState

* fix type

* fix delete index issue

* revert logic

* working version with formstate

* optimized version

* clean up code logic

* keep array length inline

* upgrade packages

* fix logic with index 0 and update with automation

* update with automation

* update automation script
@bluebill1049 bluebill1049 removed their assignment Aug 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants