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

Field validation still broken in 7.0.1 #3218

Closed
SBRK opened this issue Jul 20, 2017 · 11 comments
Closed

Field validation still broken in 7.0.1 #3218

SBRK opened this issue Jul 20, 2017 · 11 comments

Comments

@SBRK
Copy link
Contributor

SBRK commented Jul 20, 2017

The validate function is correctly called, but even if it returns a string, the meta.valid, meta.invalid and meta.error are not updated.

It is working in 6.8.0, not working in 7.0.0 and 7.0.1

EDIT: I'm seeing @@redux-form/UNREGISTER_FIELD / @@redux-form/REGISTER_FIELD actions passing when I unfocus the field. I don't see them in 6.8.0. The problem is probably coming from there

@karlshea
Copy link

karlshea commented Jul 20, 2017

Possibly more information here: #3172

@SBRK
Copy link
Contributor Author

SBRK commented Jul 21, 2017

I found the solution to the problem in #3211. The validate function needs to stay the same accross renders (ie: not a lambda generated in the render function, not an array formed directly in the render function).

@SBRK SBRK closed this as completed Jul 21, 2017
@PavelPolyakov
Copy link

hi @erikras ,

is this a final decision?

In our code we have a function which return the validation per field, like:

<Field  validate={[validate('gender')]} />

After the changes in v7 this doesn't work properly, as on each render the validation is updated. In case we want to go with v7, this forces us to define validation in the componentWillMount, which will make it looks less prettier.

Any chance that the project would go to the old behaviour?

Regards,

@danielrob
Copy link
Collaborator

@PavelPolyakov see #3211 (comment). You could also memoize this function.

@PavelPolyakov
Copy link

PavelPolyakov commented Aug 3, 2017

@danielrob
thanks for the answer.
so it means it is final. And you suggest to cache the results in the validate function?

@danielrob
Copy link
Collaborator

danielrob commented Aug 3, 2017

@PavelPolyakov not sure I follow. Memoize will cache the resulting validate function yes, as long as 'gender' doesn't change in your case. But the result of the resulting validation function each time the field value changes certainly shouldn't be cached!

@m19
Copy link

m19 commented Aug 4, 2017

I have fix it by declaring my validation function outside my React Component like this:

const validateName = [isRequired, isAlpha, minLength(2), maxLength(20)]

...

<Field
  id='firstName'
  name='firstName'
  component={Input}
  type='text'
  placeholder='First Name'
  validate={validateName}
/>

The following did NOT work in v7.0.3 and resulted in UNREGISTER_FIELD / REGISTER_FIELD actions being dispatched:

<Field
  id='firstName'
  name='firstName'
  component={Input}
  type='text'
  placeholder='First Name'
  validate=[isRequired, isAlpha, minLength(2), maxLength(20)]
/>

@PavelPolyakov
Copy link

@m19
I imagine this happens because
image

@danielrob
Do you think this is correct/expected behaviour?

@danielrob
Copy link
Collaborator

danielrob commented Aug 4, 2017

@PavelPolyakov EDIT: Pretty certain this is because minLength(2) === minLength(2) // false, which would break deepEquals for example the example still works.

@jedwards1211
Copy link
Contributor

I find myself wishing that there were a way to determine if two JS functions have all the same closure variables. It would solve this problem

@danielrob
Copy link
Collaborator

danielrob commented Jun 26, 2018

If you are hitting this issue, please see #4017

@redux-form redux-form locked as resolved and limited conversation to collaborators Jun 26, 2018
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

6 participants