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

Synchronous validation isn't performed on props change #2809

Closed
danielevns opened this issue Apr 12, 2017 · 4 comments
Closed

Synchronous validation isn't performed on props change #2809

danielevns opened this issue Apr 12, 2017 · 4 comments

Comments

@danielevns
Copy link

When a wrapped component receives new props, render is called but the synchronous validate method is not. This is problematic when validate uses props because previously valid form values may become invalid with new props. The expected behavior is for validate to be called whenever render is called.

I've reproduced the issue in a minimal example here: The input value is valid if it is greater than or equal to the counter.

I am using the latest version of redux-form (6.2.2) and React 15.5.4.

This appears to be the same issue as #1152, but I was advised to create a new issue because the previous one applied to v5.

@erikras erikras added bug and removed bug labels Apr 13, 2017
@erikras
Copy link
Member

erikras commented Apr 20, 2017

At first I thought this was a bug, but now I realize that it's more of a mild annoyance that the library already has a workaround built for.

The synchronous validation cannot be called on every prop change, because sometimes the prop changes are from the internal redux-form state. For example, when valid switches from true to false, we needn't call the synchronous validation again just because !deepEqual(props, nextProps).

However, we already have a built-in way for the library user to override the logic about whether or not to run validation. It's called shouldValidate. Below is a sandbox demonstrating how to implement shouldValidate(), specifically identifying props that your validation function needs to know if they have changed. See SyncValidationForm:15.

Edit Redux Form - Issue #2809

@erikras erikras closed this as completed Apr 20, 2017
erikras added a commit that referenced this issue Apr 20, 2017
erikras pushed a commit that referenced this issue May 9, 2017
…ializing the form (#2835)

* passing the last initialValues into initialize action if it is reinitializing the form

* Added test related to #2809

* Removed meta.touched from FieldArray props (#2836)

* Add props to the params documented in the field-level validations example (#2855)

* Fix typo in docs/api/Field.md (#2864)

* Improve SubmissionError docs (#2873)

* Add a selector to get touched and visited props from state (#2859)

* added a selector (getFormMeta) which retrieves the form.{$name}.fields slice from state

* added documentation for getFormMeta selector

* Fixed field-level validation reset bug (#2888)

* deleteInWithCleanUp needs to check if there is a value in the state before deleting. (#2876)

* deleteInWithCleanUp needs to check if there is a value in the state before deleting, to avoid Invalid KeyPath errors

* Got rid of string compare

* clean script - added es folder to be rimrafed before build (#2860)

* Add a Field's initial value to props.meta.initial (#2858)

* Add meta.initial to Field props for access to a field’s initial value.

* es6 typo

* add meta.initial to the docs for Field

* Demonstrated that calling onBlur() does not change value #2768

* Better cleanup on UNREGISTER (#2889)

* Checkbox default behavior proposal (#2863)

instead true/false to be true/'' as the current true/false breaks pristine prop

* Fancy new npm5 lock file!

* Allow direct imports to reduce bundle size. (#2893)

* Fix deep equal on maps with different structures (#2892)

* Remove references to react-router from doc page. (#2898)

* Add PropTypes for the Field components (#2862)

* Add PropTypes for the Field components

* Export fieldInputPropTypes, fieldMetaPropTypes and fieldPropTypes

* Merged with changes from #2893

* Exports defaultShouldValidate and defaultShouldAsyncValidate (#2891)

* Exports defaultShouldValidate and defaultShouldAsyncValidate

These default functions are exported for external use - particularly so
that a user can wrap the default functionality with specialised behaviour.

To resolve #2890

* Export default shouldValidates in immutable wrapper

* Allow direct imports to reduce bundle size. (#2893)

* Fix deep equal on maps with different structures (#2892)

* Remove references to react-router from doc page. (#2898)

* Add PropTypes for the Field components (#2862)

* Add PropTypes for the Field components

* Export fieldInputPropTypes, fieldMetaPropTypes and fieldPropTypes

* Merged with changes from #2893
@Limycuk
Copy link

Limycuk commented Dec 27, 2017

redux-form version 7.2.0

Sandbox doesn't work =(
shouldValidate(params) : boolean [optional] DEPRECATED #

what a new way to handle onChange nextProps?

DEPRECATED: Use shouldError() and shouldWarn(). Will be removed in v8.
will be removed shouldError and shouldWarn
or will be removed shouldValidate?

@gustavohenke
Copy link
Collaborator

shouldValidate.

@lock
Copy link

lock bot commented Dec 28, 2018

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 Dec 28, 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

4 participants