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

resetForm validates and shows errors after 4.9.0 #4323

Closed
diegocsan opened this issue Jun 20, 2023 · 7 comments
Closed

resetForm validates and shows errors after 4.9.0 #4323

diegocsan opened this issue Jun 20, 2023 · 7 comments

Comments

@diegocsan
Copy link

After updating to 4.9.0, resetForm now triggers watchers in my custom input components. When triggering these watchers, handleChange is executed, therefore generating validation errors.

I have seen from the code that 4.8.6 used to have an unwatch method.

Is there any workaround for this or a new configuration option?

@logaretm logaretm added the 🤔 needs reproduction This issue requires a demo label Jun 20, 2023
@logaretm
Copy link
Owner

logaretm commented Jun 20, 2023

A reproduction would help me determine if it is a bug or intended or something that should be implemented. Based on what you have mentioned here:

  • resetForm always mutated the current values, as to why it didn't triggers watchers on your end before, I have no clue it should if you are watching the values. I will need to see those watchers to determine that.
  • handleChange should be executed in your watchers when the value do change, if you were running them every time the watcher executes then you were under the mercy of equality === working between the watcher execution which is not ideal. Perhaps vee-validate should handle that case but would like to see an example for it first to confirm if we can do something about that or not. It maybe something that changed internally that assumes when you call handleChange then the value did change. I suspect this is the main issue here. The watchers always ran, but handleChange may not have always validated the value which could be something that changed in v4.9. but an example would help me confirm this.

@diegocsan
Copy link
Author

Thank you for your response and sorry for not providing a demo for the issue. Here is the reproduction of the error. If you change back to version 4.8.6 in the demo, you will see it works as before:

https://stackblitz.com/edit/vee-validate-v4-custom-inputs-1vmt8z?file=src%2FApp.vue

@logaretm
Copy link
Owner

logaretm commented Jun 22, 2023

validate is async, you must wait for it to finish before you try to use the data or reset the form.

Doing this will make it work

 const valid = await validate();

That should not have worked ever. Downgrading to 4.8 has the exact same effect. Feel free to provide another reproduction and I will take a look. But closing for now since doesn't seem to be an issue.

@logaretm logaretm removed the 🤔 needs reproduction This issue requires a demo label Jun 22, 2023
@diegocsan
Copy link
Author

diegocsan commented Jun 22, 2023

Sorry for the bug, I updated the demo to fix it. The problem I reported keeps happening.

Steps to replicate:

  1. Try Submit, error is shown, as expected
  2. Type in the field, no errors, as expected
  3. Submit, form is validated and cleared, but after submit an error appears
  4. Repeat in 4.8.6, the error does not appear after submit

@logaretm
Copy link
Owner

Something about your textDataChanged triggers another validation. Mainly because you call handleChange and force a validation. You need to check if the value is actually different or not than the current one before calling handleChange I suspect that's the difference here in 4.9 it will validate regardless as you have told it to specifically validate.

Not really a bug, doing this will work in your case:

if (newValue !== this.validator.value) {
    handleChange && handleChange(newValue, true);
}

https://stackblitz.com/edit/vee-validate-v4-custom-inputs-dykrvr?file=src%2FApp.vue,src%2Fcomponents%2FTextInput%2FTextInput.ts,src%2Fcomponents%2FTextInput%2FTextInput.vue

@diegocsan
Copy link
Author

That seemed to do the fix. Thank you for your help!

I have found another problem after updating the same demo to 4.10.0. I set syncVModel to true, and the form is cleared properly and so on, but now the form is validated when mounted, showing errors even with the initial values.

From what I can see, the validation is not triggered inside my handleValidatorChange function, so I think it may be something internal.

https://stackblitz.com/edit/vee-validate-v4-custom-inputs-muwc5d?file=src%2FApp.vue,src%2Fcomponents%2FTextInput%2FTextInput.ts,src%2Fcomponents%2FTextInput%2FTextInput.vue

@logaretm
Copy link
Owner

That is indeed a bug, will fix it shortly and release a patch today. Thanks for reporting it!

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

No branches or pull requests

2 participants