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

Form can be submitted when async validations are running #82

Closed
Zn4rK opened this issue Feb 19, 2018 · 3 comments
Closed

Form can be submitted when async validations are running #82

Zn4rK opened this issue Feb 19, 2018 · 3 comments

Comments

@Zn4rK
Copy link

Zn4rK commented Feb 19, 2018

What is the current behavior?

If there's any async validation happening, onSubmit will be called regardless of their status.

What is the expected behavior?

onSubmit shouldn't be called until all validators have resolved. FormState.valid is true even though it might not be true.

Sandbox Link

https://codesandbox.io/s/lv3y8mzjm

What's your environment?

final-form@4.2.0

Other information

Failing test

it('should not submit if form is still validating', () => {
  const onSubmit = jest.fn()
  const form = createForm({ onSubmit });

  const username = jest.fn()
  form.registerField('username', username, { error: true }, {
    getValidator: () => () => {
      return new Promise(resolve => resolve('Error'))
    }
  })

  form.submit()
  expect(onSubmit).not.toHaveBeenCalled()
})
@erikras
Copy link
Member

erikras commented Feb 21, 2018

A bug report with a failing test!! 😍

@erikras
Copy link
Member

erikras commented Feb 23, 2018

Published fix in v4.2.1.

@lock
Copy link

lock bot commented Feb 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants