Kendo ui 动态更改剑道UI验证程序中的错误消息?

Kendo ui 动态更改剑道UI验证程序中的错误消息?,kendo-ui,kendo-validator,Kendo Ui,Kendo Validator,我想我有两个文本字段。我可以根据文本字段更改这些错误消息吗 这里有一个例子 第一个文本框是电子邮件字段,它是必填字段。 因此,我将错误消息保存在一个数组中: ["this field is required", "enter a valid e mail"] 2文本框是必填字段。 其错误消息: ["enter a valid value in the field"] 但是在剑道ui验证程序中,像这样 var validator = $("#formID").kendoValidator

我想我有两个文本字段。我可以根据文本字段更改这些错误消息吗

这里有一个例子

第一个文本框是电子邮件字段,它是必填字段。 因此,我将错误消息保存在一个数组中:

["this field is required", "enter a valid e mail"]
2文本框是必填字段。 其错误消息:

["enter a valid value in the field"] 
但是在剑道ui验证程序中,像这样

  var validator = $("#formID").kendoValidator( 
       { messages : {
                     required : "this field is required",
                     email : "enter a valid email address"
       }
       }).data("kendoValidator"); 

如何根据文本字段错误消息动态更改这些值

您可以为
所需
电子邮件
创建
功能
,以根据html输入字段自定义错误消息。

<form id="myform">
    <input name="username" required /> <br />
    <input type="email" name="userEmail" required data-message="My custom email message" /> <br />
    <button>Validate</button>
</form>



验证
脚本部分:

<script>
     $("#myform").kendoValidator({
             messages: {
                 // defines a message for the 'custom' validation rule
                 custom: "Please enter valid value for my custom rule",

                 // overrides the built-in message for the required rule
                 required: function(input) {
                     return getRequiredMessage(input);
                 },

                 // overrides the built-in message for the email rule
                 // with a custom function that returns the actual message
                 email: function(input) {
                     return getMessage(input);
                 }
             },
             rules: {
               custom: function(input) {
                 if (input.is("[name=username]")) {
                     return input.val() === "Tom";
                 }
                 return true;
               }
             }
        });

        function getMessage(input) {
          return input.data("message");
        }
        function getRequiredMessage(input) {
           if (input.is("[name=username]")) {
                     return "User name is required";
                 }
            else
                 return input.attr("name") + " Field is Required";
        }
</script>

$(“#myform”).kendoValidator({
信息:{
//为“自定义”验证规则定义消息
自定义:“请为我的自定义规则输入有效值”,
//覆盖所需规则的内置消息
必需:功能(输入){
返回getRequiredMessage(输入);
},
//覆盖电子邮件规则的内置邮件
//使用返回实际消息的自定义函数
电子邮件:功能(输入){
返回getMessage(输入);
}
},
规则:{
自定义:函数(输入){
if(input.is(“[name=username]”){
返回input.val()=“Tom”;
}
返回true;
}
}
});
函数getMessage(输入){
返回输入数据(“消息”);
}
函数getRequiredMessage(输入){
if(input.is(“[name=username]”){
返回“用户名为必填项”;
}
其他的
返回输入。attr(“name”)+“字段是必需的”;
}

getRequiredMessage
function i中,根据输入名称自定义错误消息

我为输入用户名提供了“用户名是必需的”。如果愿意,您甚至可以从数组中提供错误消息