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

Error when submit form with asyncValidate and asyncChangeFields #3658

Closed
swarthy opened this issue Dec 4, 2017 · 5 comments
Closed

Error when submit form with asyncValidate and asyncChangeFields #3658

swarthy opened this issue Dec 4, 2017 · 5 comments

Comments

@swarthy
Copy link

swarthy commented Dec 4, 2017

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

When submit form with asyncValidate and asyncChangeValues got error because of that line:
https://github.com/erikras/redux-form/blob/master/src/handleSubmit.js#L95
asyncValidate called with no arguments, so here
https://github.com/erikras/redux-form/blob/master/src/createReduxForm.js#L684-L689
after webpack build conditions are inlined:

var fieldNeedsValidation =
  !submitting &&
  trigger === 'blur'
    ? !asyncBlurFields || ~asyncBlurFields.indexOf(name.replace(/\[[0-9]+\]/g, '[]'))
    : !asyncChangeFields || ~asyncChangeFields.indexOf(name.replace(/\[[0-9]+\]/g, '[]'));              

trigger is not blur (its undefined, like all other args), asyncChangeFields is array

What is the expected behavior?

Do not throw error?

Sandbox Link

Example: JSFiddle

What's your environment?

React 16.2.0
Redux-Form 7.2.0
Ubuntu 17.10 Google Chrome 62.0.3202.94

Other information

Error stacktrace

Uncaught TypeError: Cannot read property 'replace' of undefined
    at Form._this.asyncValidate (VM731 redux-form.js:7774)
    at handleSubmit (VM731 redux-form.js:9630)
    at Form._this.submit (VM731 redux-form.js:7816)

UPD: My bad, code is ok, looks like it's babel/webpack issue?
source:

            const fieldNeedsValidation =
              !submitting &&
              (formHasAsyncFields ||
                (trigger === 'blur'
                  ? fieldNeedsValidationForBlur
                  : fieldNeedsValidationForChange))

after translation no parentheses (in JSFiddle too):

var fieldNeedsValidation = !submitting && trigger === 'blur' ? !asyncBlurFields || ~asyncBlurFields.indexOf(name.replace(/\[[0-9]+\]/g, '[]')) : !asyncChangeFields || ~asyncChangeFields.indexOf(name.replace(/\[[0-9]+\]/g, '[]'));
@andybustamante
Copy link

I'm having the same issue and see the same error stacktrace.

Uncaught TypeError: Cannot read property 'replace' of undefined
    at Form._this.asyncValidate (VM731 redux-form.js:7774)
    at handleSubmit (VM731 redux-form.js:9630)
    at Form._this.submit (VM731 redux-form.js:7816)

@dagstuan
Copy link
Contributor

I had the same issue when using 7.2.0, had to revert my project to 7.1.2 since the issue was introduced in 7.2.0. This was introduced with #3531.

@imrekoszo
Copy link
Contributor

Pushed a proposed fix to #3733

@erikras
Copy link
Member

erikras commented Jan 18, 2018

Published fix in v7.2.1.

@lock
Copy link

lock bot commented Jan 18, 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 Jan 18, 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

5 participants