matfish2 / vue-formular

a comprehensive vue.js form component
https://www.npmjs.com/package/vue-formular
MIT License
43 stars 11 forks source link

how to get programmatically if form has validation errors #8

Closed rkrishnamoorthy closed 8 years ago

rkrishnamoorthy commented 8 years ago

Hi I have a question. I would like to disable the submit button on a form if the form has errors. But i would like to do it based on a computed field which looks at the field and also a values of a few other fields and then indicates whether the submit button should be enabled


computed: {
    canSubmit: function() {
        // how do i check here whether form has validation errors based on rules defined for fields ?
    }

}
matfish2 commented 8 years ago

Find the form instance using v-ref, and check the length of the errors property.

 canSubmit: function() {
      return !this.$refs.form.errors.length;
 }

I plan to add an hasErrorsor isValid method to do the same.

rkrishnamoorthy commented 8 years ago

Thank you ! worked perfectly