question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] manual or reactive trigger of v-text-field rules' validation

See original GitHub issue

Problem 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.',
},
  1. The validation doesn’t initially occur until clicking on the input.
  2. When changing one of the values, the error [dis]appears only on the current field, but stays displayed on the other one.
  3. 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:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
scscgitcommented, Jun 24, 2021

Note regarding duplicate issues:

  • they don’t cover the scenario of reactive triggering (native to Vue) when a variable dependency (of a rule) referenced in the function changes
  • #8698 probably only requires documenting the API for individual inputs
  • #3530 (together with the previous issue) lacks the opposite scenario where we want to avoid ‘untouched’ inputs also immediately displaying their validation errors, as this side effect always occurs once we start to use the validate() workaround

Also 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/dypNbze

0reactions
KaelWDcommented, Jun 23, 2021

Duplicate of #8698 and maybe #3530

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - how to validate both input fields when one updates
By default, a vuetify input's validation logic only triggers when the value bound to that input changes. In order to trigger the validation...
Read more >
Fixing Vuetify's Form Validation. Quite ... - Robert Mirabelle
Once the the form's submit button is clicked, manually trigger validation by first hot-updating rules to use actual rules. Then, wait for the...
Read more >
vee-validate: Versions - Openbase
Fixed an issue where computed rules triggered validation before the field was explicitly validated (via event trigger or calling validate ).
Read more >
Text field component - Vuetify
Validation. Vuetify includes simple validation through the rules prop. The prop accepts a mixed array of types function , boolean and string . ......
Read more >
Knowledge Base - RapiseDocs
Rapise is a test automation platform for desktop, web and mobile applications. It is designed for building automated and manual end-to-end UI tests...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found