Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda