[Vuejs]-Vue.js – Element UI – get the state of form validation

0👍

Basically you watch ruleForm – so everytime ruleForm changes you trigger checkform – but your validtor triggers on blur after you set ruleForm so you first test then turn valid. change this into a getter:

get formValid(){

   const fields = this.$refs.ruleForm.fields || [];
    if (fields.find((f) => f.validateState === 'validating')) {
      setTimeout(() => {
        this.checkForm();
      }, 100);
    }
    return fields.reduce((acc, f) => {
      const valid = (f.isRequired && f.validateState === 'success');
      const notErroring = (!f.isRequired && f.validateState !== 'error');
      return acc && (valid || notErroring);
    }, fields.length > 0);
} 

Leave a comment