How to clear the validation prompt in element form validation

How to clear the validation prompt in element form validation

Problem scenario:

Recently, when developing a project, I encountered such a problem:
When checking the data in the form field, there is one special item. It is not a simple input box, drop-down box or other form elements, but an el-table selection pop-up window written by myself. My check for it is as follows:

protocolId:
   { required: true, message: 'Please select the parsing protocol', trigger: 'blur'},
],

This can realize the verification function, but there will be a problem. If the verification condition (submit button) is triggered and an error message is prompted, the error message will still exist even if the data is reselected later, because the submit button is not clicked again to trigger the verification. This user experience is not very good.


Solution:

1. Check the fields individually

Click the Save button to trigger the validation, which generally validates all fields. form component in element-ui also provides a function to validate a field, which can be used as follows:

this.$refs.addForm.validateField('protocolId', (valid) => {
 	//valid returns the error message written in the rule set. If the conditions are met, the return value is empty if (!valid) {
         return 
     }
 })

The above code can be executed in a function that confirms data selection, so that this special content is checked again. If it meets the verification rules, the error prompt disappears.

2. Directly clear the prompt information of the field under the form field

this.$refs.addForm.clearValidate();

This method is to directly clear the error message without making any judgment. I personally do not recommend it.

This concludes this article on how to clear verification prompts for element form validation. For more information on clearing verification prompts for element form validation, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue uses element-ui to implement form validation
  • Use element-ui + Vue to solve the problem of form validation in table
  • Vue element custom form validation requests backend interface validation
  • Detailed explanation of three ways of form validation in element-ui
  • Implementation of Vue elementui form validation
  • Example code for form validation using element-ui in vue
  • Problems encountered in Form validation of Vue ElementUI
  • Implementation of element custom form verification uploading the front and back of the ID card

<<:  Use Meta tag code to set 360 Dual-core Browser to default to high-speed mode instead of compatible mode

>>:  How does MySQL connect to the corresponding client process?

Recommend

18 killer JavaScript one-liners

Preface JavaScript continues to grow and prosper ...

Several ways to encapsulate axios in Vue

Table of contents Basic Edition Step 1: Configure...

MySQL 8.0.15 installation tutorial for Windows 64-bit

First go to the official website to download and ...

Causes and solutions for MySQL too many connections error

Table of contents Brief summary At noon today, th...

Solution to data duplication when using limit+order by in MySql paging

Table of contents summary Problem Description Ana...

A brief understanding of MySQL SELECT execution order

The complete syntax of the SELECT statement is: (...

Detailed explanation of the difference between run/cmd/entrypoint in docker

In Dockerfile, run, cmd, and entrypoint can all b...

How to install golang under linux

Go is an open source programming language that ma...

Detailed description of the use of advanced configuration of Firewalld in Linux

IP masquerading and port forwarding Firewalld sup...

You may not know these things about Mysql auto-increment id

Introduction: When using MySQL to create a table,...

The phenomenon of margin-top collapse and the specific solution

What is margin-top collapse Margin-top collapse i...

Some tips for using less in Vue projects

Table of contents Preface 1. Style penetration 1....