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

validate does not trigger with new initialValues #4782

Open
glecompte opened this issue Apr 7, 2023 · 9 comments · May be fixed by #4786
Open

validate does not trigger with new initialValues #4782

glecompte opened this issue Apr 7, 2023 · 9 comments · May be fixed by #4786
Labels

Comments

@glecompte
Copy link

When the form is passed a new initialValues prop the validate function does not fire.

This happens with redux-form 8.3.10 but not on 8.3.9 or below.

On initial load of the form the validate function fires as expected. Upon passing the form a new initialValues prop, validate does not fire as I would expect.

@glecompte glecompte added the bug label Apr 7, 2023
@dargonwanglong
Copy link

I also encountered this bug.

@cpoftea
Copy link

cpoftea commented Aug 23, 2023

Confirming bug. Validation errors are kept between initialValues changes with enableReinitialize option

@Sojborg
Copy link

Sojborg commented Sep 4, 2023

I get this to. Anyone who have an workaround?

@cpoftea
Copy link

cpoftea commented Sep 4, 2023

Anyone who have an workaround?

@Sojborg Only with patching a single line of code with patch-package for v8.3.10. But use it at your own risk.

--- a/node_modules/redux-form/es/createReduxForm.js
+++ b/node_modules/redux-form/es/createReduxForm.js
@@ -138,7 +138,7 @@ export default function createReduxForm(structure) {
                   updateUnregisteredFields: nextProps.updateUnregisteredFields
                 });
 
-                return true;
+                return false;
               }
             } else if (_this.props.initialValues && (!_this.props.initialized || enableReinitialize)) {
               _this.props.initialize(_this.props.initialValues, _this.props.keepDirtyOnReinitialize, {

@Sojborg
Copy link

Sojborg commented Sep 4, 2023

Thanks @cpof-tea! Did you try to make a PR with this change?

@cpoftea
Copy link

cpoftea commented Sep 4, 2023

@Sojborg Actually, I don't have time to check if the original behavior is intended or a bug. Also, I can't say if this patch can break something or not

@pnogier
Copy link

pnogier commented Sep 13, 2023

Anyone who have an workaround?

@Sojborg Only with patching a single line of code with patch-package for v8.3.10. But use it at your own risk.

--- a/node_modules/redux-form/es/createReduxForm.js
+++ b/node_modules/redux-form/es/createReduxForm.js
@@ -138,7 +138,7 @@ export default function createReduxForm(structure) {
                   updateUnregisteredFields: nextProps.updateUnregisteredFields
                 });
 
-                return true;
+                return false;
               }
             } else if (_this.props.initialValues && (!_this.props.initialized || enableReinitialize)) {
               _this.props.initialize(_this.props.initialValues, _this.props.keepDirtyOnReinitialize, {

Hi, does anyone encountered any issue using this patch ?

@Sojborg
Copy link

Sojborg commented Sep 16, 2023

@pnogier I'm using it and it works in my project and I'm using it in a larger company app with multiple forms with many form elements.

@cpoftea
Copy link

cpoftea commented Sep 18, 2023

Thanks @cpof-tea! Did you try to make a PR with this change?

@Sojborg I will open a PR in a few days then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants