Sunday, 6 October 2019

With VeeValidate, how can I see if a field has been touched and is valid?

I'm trying:

  computed: {
    isFormValid() {
      let isValid = this.$validator.fields.some(field => {
        console.log(field.flags);
        return field.flags.touched; || field.flags.invalid;
      });
      console.log("isValid", isValid);
      return isValid;
    }
  },

But this gives an error with: "TypeError: this.$validator.fields.some is not a function"

So then I figured let me iterate over the observable:

      let isValid = Array.from(this.$validator.fields).some(field => {
        console.log(field.flags);
        return field.flags.touched; //|| field.flags.invalid;
      });

Yay! Progress! No more error. But it doesn't recompute when I change the form input values.

So how can I do this?



from With VeeValidate, how can I see if a field has been touched and is valid?

No comments:

Post a Comment