简体   繁体   English

vuelidate - 如何使用内置验证器显示自定义验证消息

[英]vuelidate - How to display custom validation message with built-in validators

I am using vuelidate library for validating my forms.我正在使用 vuelidate 库来验证我的表单。 I have to use the built-in validators with the custom message.我必须将内置验证器与自定义消息一起使用。 I have tried below.我在下面尝试过。 But not working.但不工作。 Ref: Vuelidate Form validation library参考: Vuelidate 表单验证库

validations() {
   return {
     email: {
       requiredIf: requiredIf(() => {
         return this.data.enablevalidation;
       }),
       email: helpers.withMessage(this.data.validation_err_message, email),
     },
   };
},

my problem is, If the validation is false, still its validating the email also.我的问题是,如果验证是假的,它仍然在验证电子邮件。 Validation should be pass based on the both condition.验证应该基于这两个条件通过。 If validation false, Email validation also should not work.如果验证错误,电子邮件验证也不应该起作用。 How to achieve this scenario如何实现这个场景

We have to use the helpers with functional method to achieve this.我们必须使用具有功能方法的助手来实现这一点。

validations () {
   return {
     email: {
       requiredIf: helpers.withMessage(this.data.validation_err_message, 
          requiredIf(() => {
            return this.data.enablevalidation
       })),
       email: helpers.withMessage(this.data.validation_err_message, email),
     }
   }
},

Initiallty it will validate, whether this field have to validate or not. Initiallty 它将验证,该字段是否必须验证。 If validation is true, It will display the given message.如果验证为真,它将显示给定的消息。 Email will be validate if given wrong.如果输入错误,电子邮件将被验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM