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

submitOnChange validates form with previous values #72

Open
chawes13 opened this issue Dec 1, 2020 · 0 comments
Open

submitOnChange validates form with previous values #72

chawes13 opened this issue Dec 1, 2020 · 0 comments

Comments

@chawes13
Copy link
Contributor

chawes13 commented Dec 1, 2020

Expected: On change of an input, validations are run and the form is submitted (if no validations failed)
Actual: On change of an input, validations are run against the previous values and the form does not submit

Sandbox: https://codesandbox.io/s/redux-form-synchronous-validation-forked-uborp?file=/SyncValidationForm.js (type a single letter into the username input)

Related redux-form issues: redux-form/redux-form#537, redux-form/redux-form#4177

Suggested solution: Wrap props.submit() in a timeout to ensure that the form has the latest values
Workaround: Instead of passing submitOnChange: true to lpForm, we can override the change handler like so

onChange: (_values, _dispatch, props) => {
        setTimeout(props.submit, 0)
    },
@chawes13 chawes13 changed the title submitOnChange receives previous errors object submitOnChange submits form with previous values Dec 1, 2020
@chawes13 chawes13 changed the title submitOnChange submits form with previous values submitOnChange validates form with previous values Dec 1, 2020
@dpikt dpikt removed their assignment Dec 1, 2020
@dpikt dpikt added this to the v2 Enhancements milestone Dec 1, 2020
@chawes13 chawes13 modified the milestone: v2 Enhancements Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants