Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
How to trigger validation without clicking button in vue

I am using async-validator for my validation because I am using element ui. Here is my form and my validation rules:

<el-form :model="ance" :rules="validationRules" ref="form">
                <el-form-item prop="files">
                  <files-selector v-model="ance.files" />
                </el-form-item>
              </el-form>

validationRules: function () {
      return {
        files: [
          {
            required: true,
            trigger: 'blur',
            message: 'Form required',
          },
        ],
      };
    },

files-selector is my child component and includes el-cascader inside:

<template>
  <div>
    <el-cascader
      v-model="files"
      :options="filesOptionsForCascader"
      placeholder="Files"
      filterable
      :filter-method="filterMethod"
      :props="{
        emitPath: false,
      }"
    />
  </div>
</template>

When I click the button it triggers the validation:

saveAnce() {
      this.$refs.form.validate((isValid) => {
        if (!isValid) {
          return;
        }
        //post request
      });
    },

But my problem is, I click the button without selecting anything from files-selector and it gives me the message Form required. After, I select from files-selector but the message is still being shown and even validation doesnt fail, I cannot get rid of this view.

after selection

What can I do to solve this? Should I add watcher to see if the file selector is not empty? Form example could validation without clicking button solve this? Any help would be appreciated.

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You should call this.$refs.form.clearValidation() to remove the validation errors - as explained in https://element.eleme.io/#/en-US/component/form#form-methods

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!