如何为 kendo 网格编辑器配置自定义验证规则
How to configure custom validation rules for kendo grid editor
我们有 ASP.NET MVC 应用程序使用 Telerik UI for ASP.NET MVC。通过kendo html helper.
在页面上设置了一个带有弹出编辑器的网格。
现在我需要为弹出编辑器表单配置一些自定义验证规则。我找不到如何去做的方法。
- 在验证器文档中可以看到从
$("form")
获取验证器参考。但是grid popup 里面没有表格
- 如果我在取自
$("gridName").kendoValidator().data("kendoValidator")
的验证器上配置规则,则在保存编辑器更改时不会触发此类规则
- 例如,如果我从某个编辑器容器
gridOnEditEvent.container.find("#editorcontent").kendoValidator().data("kendoValidator")
获取对验证器的引用,我可以手动扩展规则、验证和发送表单数据,但弹出编辑器的标准保存按钮不会反映此类配置
如何扩展网格弹出编辑器验证器的验证规则?
Kendo 使用 HTML 助手构建的小部件,例如网格,initialize their own internal Validator. Custom rules must be added to the Validator class itself in order to run in these inaccessible instances of the Validator. Telerik has an example 如何做到这一点:
$.extend(true, kendo.ui.validator, {
rules: { // custom rules
productnamevalidation: function(input, params) {
if (input.is("[name='ProductName']") && input.val() != "") {
input.attr("data-productnamevalidation-msg", "Product Name should start with capital letter");
return /^[A-Z]/.test(input.val());
}
return true;
}
},
messages: { //custom rules messages
productnamevalidation: function(input) {
// return the message text
return input.attr("data-val-productnamevalidation");
}
}
});
我们有 ASP.NET MVC 应用程序使用 Telerik UI for ASP.NET MVC。通过kendo html helper.
在页面上设置了一个带有弹出编辑器的网格。现在我需要为弹出编辑器表单配置一些自定义验证规则。我找不到如何去做的方法。
- 在验证器文档中可以看到从
$("form")
获取验证器参考。但是grid popup 里面没有表格
- 如果我在取自
$("gridName").kendoValidator().data("kendoValidator")
的验证器上配置规则,则在保存编辑器更改时不会触发此类规则 - 例如,如果我从某个编辑器容器
gridOnEditEvent.container.find("#editorcontent").kendoValidator().data("kendoValidator")
获取对验证器的引用,我可以手动扩展规则、验证和发送表单数据,但弹出编辑器的标准保存按钮不会反映此类配置
如何扩展网格弹出编辑器验证器的验证规则?
Kendo 使用 HTML 助手构建的小部件,例如网格,initialize their own internal Validator. Custom rules must be added to the Validator class itself in order to run in these inaccessible instances of the Validator. Telerik has an example 如何做到这一点:
$.extend(true, kendo.ui.validator, {
rules: { // custom rules
productnamevalidation: function(input, params) {
if (input.is("[name='ProductName']") && input.val() != "") {
input.attr("data-productnamevalidation-msg", "Product Name should start with capital letter");
return /^[A-Z]/.test(input.val());
}
return true;
}
},
messages: { //custom rules messages
productnamevalidation: function(input) {
// return the message text
return input.attr("data-val-productnamevalidation");
}
}
});