[Feature Request] manual or reactive trigger of v-text-field rules' validation
See original GitHub issueProblem to solve
When using rules
in v-text-field
, “When the input value changes, each element in the array will be validated.” Based on this definition, the validation event occurs only for the specific v-text-field that changes, without an option to trigger it manually; not even by clicking on the input. As a basic use-case, this may be necessary whenever validation conditions depend on any state of other inputs.
Repro steps on Vuetify v2.3.21: https://codepen.io/cTAlENtATI/pen/WNGoyvq
<v-text-field v-model="email1" :rules="[rules.email1]" />
<v-text-field v-model="email2" :rules="[rules.email2]" />
rules: {
email1: value => value !== this.email2 || 'E-mails must differ.',
email2: value => value !== this.email1 || 'E-mails must differ.',
},
- The validation doesn’t initially occur until clicking on the input.
- When changing one of the values, the error [dis]appears only on the current field, but stays displayed on the other one.
- Unlike point 1, clicking on the other field doesn’t fix the validation issue until you start to type in a new input.
Proposed solution
At the very least, I would request for a workaround to be officially documented. As a feature suggestion, first option could be some manual trigger/prop to re-compute all validations, and a second option could be to reactively watch (in Vue-style) on the variables used in the (anonymous) rule function, so that it’ll re-validate when they change (making it trivial to combine with other reactive component properties).
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Note regarding duplicate issues:
validate()
workaroundAlso about the last
nextTick()
-workaround-requiring issue that I had described (which is caused by Vue, but could be worth addressing if we have to use workarounds), I apologize that I wasn’t able to find time to properly analyze the root cause; but for anyone interested, here is my work-in-progress codepen where I was debugging how the issue only occurs between different email pairs: https://codepen.io/cTAlENtATI/pen/dypNbzeDuplicate of #8698 and maybe #3530