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

validation error caused by validateOnBlur after array field is deleted #408

Closed
shrugs opened this issue Apr 17, 2018 · 3 comments
Closed
Labels

Comments

@shrugs
Copy link

shrugs commented Apr 17, 2018

when following validateOnBlur, mobx-react-form attempts to validate a field on blur using a debounce, but if the parent field is deleted before this debounce timeout expires, the validator attempts to invalidate a non-existent field, causing a (Error): Validation Error: Invalid Field Instance

This occurs when:

  1. focus an input for a parentField's nested field
  2. click the remove button (which calls parentField.onDel)
  3. wait a few ms for the debouncer
  4. Invalid Field Instance thrown because, indeed, the field instance no longer exists

A (horrible) workaround at the moment is to simply delay the removal of the field until after validation has occurred.

_remove = () => {
    setTimeout(() => {
      this.props.field.del()
    }, 251) // default validationDebounceWait is 250ms
  }
@shrugs
Copy link
Author

shrugs commented Apr 17, 2018

I was unable to disable validation just-in-time because the debounce is scheduled immediately after the input is defocused, and before the event to remove the field is received, so there's no way to cancel it.

One option would be to disable validateOnBlur altogether and implement it ourselves, only calling the validate function if the removal event was not called within some duration.

@shrugs
Copy link
Author

shrugs commented Apr 17, 2018

I was able to obscure the removal delay by using some nice css transitions, so this isn't realistically the worst thing in the world anymore.

@foxhound87
Copy link
Owner

Related to:
#371
#399

@foxhound87 foxhound87 added the fix label Oct 27, 2018
foxhound87 added a commit that referenced this issue Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants