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

JavaScript to achieve time range effect

This article shares the specific code for JavaScr...

Hbase installation and configuration tutorial under Linux

Table of contents Hbase installation and configur...

JavaScript flow control (loop)

Table of contents 1. for loop 2. Double for loop ...

How to get the dynamic number of remaining words in textarea

I encountered a case at work that I had never wri...

Web Design TabIndex Element

TabIndex is to press the Tab key to sequentially o...

Textarea tag in HTML

<textarea></textarea> is used to crea...

Docker runs operations with specified memory

as follows: -m, --memory Memory limit, the format...

18 Web Usability Principles You Need to Know

You can have the best visual design skills in the...

How to make a div height adaptive to the browser height

This old question has troubled countless front-end...

Use HTML to write a simple email template

Today, I want to write about a "low-tech&quo...

Several ways to store images in MySQL database

Usually the pictures uploaded by users need to be...