Learn how to use text fields for positive validation and send data
P粉574695215
P粉574695215 2023-08-09 18:56:19
0
1
575
<p>I have a <code>v-text-field</code> with validation rules that trigger something when focus is lost. </p> <pre class="brush:php;toolbar:false;"><v-text-field :rules="validationRules" @blur="emitFunction" ></v-text-field></pre> <p>Is there a way to only call <code>emitFunction</code> when validation passes? </p>
P粉574695215
P粉574695215

reply all(1)
P粉025632437

You can wrap it with v-form and use v-model to track the validity of the form

const isValid = ref(false)
function emitIfValid() {
  if (isValid.value) emitFunction()
}
<v-form v-model="isValid">
  <v-text-field
    :rules="validationRules"
    @blur="emitIfValid"
  />
</v-form>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template