-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Validation behavior when removing rows from field array #4017
Comments
Sorry for the late reply. This is a tricky one since the validation occurs because the last answer value seems to have been changed. This isn't correct of course but because of a race condition, the value swapping happens after the old field was removed making the new value I will try to fix this, but as a workaround, you could disable |
All right I see, that sounds pretty annoying. A fix would be nice, but the workaround is totally fine for us! So thanks for pointing me in the right direction - I hadn't though of that possibility |
I found that a few days ago, new feature were added:fix: only validate when one of the setters is ran closes Is this a broken change ?
An example(used vee-validate@4.8.4): https://codesandbox.io/s/vibrant-knuth-sm3ds2?file=/src/App.vue In the latest version, this will not work because the validator will not triggered. Will you consider forward compatibility? And if child component use
function setValue(newValue, shouldValidate = true) {
value.value = newValue;
if (!shouldValidate) {
validateValidStateOnly();
return;
}
const validateFn = shouldValidate ? validateWithStateMutation : validateValidStateOnly;
validateFn();
}
const valueProxy = computed({
get() {
return value.value;
},
set(newValue) {
setValue(newValue, validateOnValueUpdate);
},
}); |
@jusheng27
Mutating the
I don't think we should bring the watch behavior back, validations should run explicitly as a result of the value changing intentionally not as a side effect of:
This makes the validation more predictable and avoids some of the issues seen with FieldArrays and virtual fields. 3 distinct bugs were caused by the watcher in field arrays combined with some edge cases.
Yes, we can certainly fix it. Can you create an issue with a reproduction? |
Ok, I see, I'll try to change the usage in our project( Change the value of useField directly ). Thanks for your reply.
|
What happened?
When removing rows from a field array the validation is triggered for some of the remaining rows (seems like always the last untouched row is affected).
Reproduction steps
Version
Vue.js 3.x and vee-validate 4.x
What browsers are you seeing the problem on?
Relevant log output
No response
Demo link
https://codesandbox.io/s/amazing-wright-n9bjih
Code of Conduct
The text was updated successfully, but these errors were encountered: