Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to clear the check prompt for element form validation

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to clear element form verification hints, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Problem scenario:

Recently, when I was developing a project, I encountered such a problem:

When checking the data in the form field, there is a special item, which is not a simple input box, drop-down box and other form elements, but an el-table selection pop-up window written by myself. My verification is as follows:

ProtocolId: [{required: true, message: 'please select a resolution protocol', trigger: 'blur'},]

This can achieve 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 re-selected later, because the submit button is not clicked again to trigger the check. So the user experience is not very good.

Solution: 1. Check the field separately

Click the Save button to trigger verification, which usually verifies all fields. The form form component in element-ui also provides a function to verify a field, as shown below:

This.$refs.addForm.validateField ('protocolId', (valid) = > {/ / valid returns the error message written in the rule set. If the condition is met, an empty if (! valid) {return}} is returned)

The above code can be executed in a function that confirms the data selection, so that this particular item is checked again, and if the verification rules are met, the error prompt disappears.

two。 Directly clear the prompt information for this field under the form field this.$refs.addForm.clearValidate ()

This method is to directly clear the error message, do not make any judgment, the individual is not too recommended to use

The above is all the content of the article "how to clear the check prompt for element form validation". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report