react-validation icon indicating copy to clipboard operation
react-validation copied to clipboard

Removed inputs is not removed from validation

Open maxtotheguenther opened this issue 6 years ago • 9 comments

I have a dynamic form where you can add and delete participants. If I delete a participant (via Redux) the fields of the deleted form are still in the validation (form.getValues). How do I get the input out of validation, after deleting a participant.

maxtotheguenther avatar Jun 20 '18 12:06 maxtotheguenther

I am experiencing the same issue. How can I force validation to "forget" about properties no longer being rendered?

groos avatar Jun 20 '18 21:06 groos

@maxtotheguenther We discovered that the issue is with a race condition inside _unregister in hocs/forms/index.js. When a validated field unmounts and unregisters, it can sometimes re-add other unmounted fields back into the form. This can be fixed by passing the prevState param into setState inside _unregister, and modifying prevState instead of this.state.

groos avatar Aug 22 '18 17:08 groos

I'm having the same issue - still no update? This library is more and more frustrating

graham-saunders avatar Sep 06 '18 14:09 graham-saunders

@maxtotheguenther We discovered that the issue is with a race condition inside _unregister in hocs/forms/index.js. When a validated field unmounts and unregisters, it can sometimes re-add other unmounted fields back into the form. This can be fixed by passing the prevState param into setState inside _unregister, and modifying prevState instead of this.state.

Hope you don't mind me asking but I'm new to editing npm modules. Could you elaborate on what you did? Here's what I've tried

  • Edit code in node_modules, yarn build. I get an error saying the build.js script is not available.
  • Not sure how "pass prevState param into setState in _unregister"

Any help here would be appreciated. Are you aware of anything else this fix could break?

risaWY avatar Dec 02 '18 20:12 risaWY

Here is the edited code with my change described above. Look for "prevState" to see the changes. You should be able to import this file into your code, instead of this library.

https://pastebin.com/7GgM910k

groos avatar Dec 03 '18 21:12 groos

@groos Thanks for the response man. I'll try out the code when I get off work. Did you try making a pull request with the author? Would be great if everyone else don't encounter what we did...

risaWY avatar Dec 03 '18 23:12 risaWY

@groos I think we're getting real close and it might just be my lack of experience. I tried importing the file directly instead of the library and I get an error saying 'define' is not defined. I removed the part of the file that involves "define" and I was able to create a HOC form and it worked!

I googled something about "define" and it's something to do with backend. All this is running in the browser so I think we're ok?

Also, I looked at node_modules/react-validation/build/main.js (which your file is based on) and that thing uses "define". I'm wondering how that works but not when I import your file directly...

If you don't have the time to respond to that, thank you very much anyway!

risaWY avatar Dec 04 '18 07:12 risaWY

@risaWY Glad to hear you got it working. @ssartell also deserves some credit for helping debug this issue.

If the author @Lesha-spr can reply here to verify this library is indeed still being maintained, I would be happy to create a PR. That pastebin link is set to never expire, for any readers visiting from the future.

groos avatar Dec 04 '18 15:12 groos

@groos @ssartell Thank you 3,000 times. It's working.

watcharakrit avatar May 07 '19 11:05 watcharakrit