0

I'd like to remove the error when I have focus on my input. Here is my input:

      <v-text-field
        v-model="models.codePostal"
        label="Code postal"
        :rules="regles.codePostal"
        :hint="this.models.communeResidence.codePostal!==''?`Pourrait être ${this.models.communeResidence.codePostal}`:''"
        hide-details="auto"></v-text-field>

I thought I could add

@focus="error=false"

But it doesn't work. Does anybody have an idea? It may not be possible. Thanks.

2

1 Answer 1

2

Use reset method on focus event.

<v-text-field
  @focus="reset()"
  ref="field"
  v-model="models.codePostal"
  label="Code postal"
  :rules="regles.codePostal"
  :hint="this.models.communeResidence.codePostal!==''?`Pourrait être ${this.models.communeResidence.codePostal}`:''"
  hide-details="auto"
></v-text-field>
 methods: {
    reset() {
      this.$refs.field.reset()
    }

Or resetValidation() method in the same way if you don't want to clear the field.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it does work for the error, but it clears the input, what is not really good if the user only has to change a character.
@djcaesar9114 If you don't want to clear the field then use resetValidation() instead of reset()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.