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] Validate a single field

See original GitHub issue

Problem to solve

I need to just validate one of the fields in the form to do some processing like .validate('email') to used to send a E-mail verification code in the register form. According to the documentation, I used vee-validate.But I encountered another problem: https://github.com/baianat/vee-validate/issues/2219 If vuetify has this feature, I don’t need to use other authentication components.It It took me too much time.

Proposed solution

<v-form ref="form">
  <v-text-field label="E-mail" name="email">
  </v-text-field>
  <v-text-field label="Mobile" name="mobile">
  </v-text-field>
  <v-text-field label="Addr." name="address">
  </v-text-field>
</v-form>
// single
$refs.form.validate('email')
// multiple
$refs.form.validate(['email', 'mobile'])
// All
$refs.form.validate() // existing

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:71
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rashadriveracommented, May 4, 2021

I have another case where this feature would be useful.

In the case where we have 2 input fields for dates (lets say the first is StartDate and the second is EndDate). There is a common validation practice to ensure that the StartDate is always after the EndDate. Well, in the case of Vue, if the user triggers validation on both (which is not usual, but can happen when someone is not paying attention), fixing the first field will not remove the validation error on the second. The only way to resolve this is to instruct the user to change the second input field so a revalidation occurs. It would be better if we could invoke an individual validation on the second fields when the first passes validation.

Alternatively, I suggest a method that will clear an error for a specific field. So in this scenario, when one of the dates passes validation, we could clear the error on the second. This approach poses other issue such as follow-on validation that might have other validation issues.

One thing to note, there is the potential reclusiveness as we’ve experienced when invoking the current validate method. I am open to better ideas and suggestions.

1reaction
johnleidercommented, Sep 16, 2021

resolved by #14026

Vuetify 3 validation is lazy by default now. You can use a ref on the input to manually validate it.

<v-text-field ref="field" @blur="$refs.field.validate()" />

You also have access to a v-validation component which provides you with more flexibility:

<v-validation :rules="[rules]">
  <template #default="{ validate, reset, resetValidation, ...etc }">
    <input @blur="validate">
  </template>
</v-validation>

If you have any questions, please reach out to us in our Discord community.

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 >
Validate a field only if another one passes validation - Laracasts
I have a form request that needs to validate 2 fields. However, I need to validate one of the fields only if the...
Read more >
Validation - Laravel - The PHP Framework For Web Artisans
To learn about Laravel's powerful validation features, let's look at a complete example of validating a form and displaying the error messages back...
Read more >
Field validation for forms | The Jotform Blog
Field validation is an automated process of ascertaining that each field contains the correct value before the form is accepted. The concept is ......
Read more >
How to validate a field in a Service Request - Ivanti Community
2, it is not possible to add a validation rule in a Request Offering template field configuration. This article describes how to add...
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