如何为 kendo 网格编辑器配置自定义验证规则

How to configure custom validation rules for kendo grid editor

我们有 ASP.NET MVC 应用程序使用 Telerik UI for ASP.NET MVC。通过kendo html helper.

在页面上设置了一个带有弹出编辑器的网格。

现在我需要为弹出编辑器表单配置一些自定义验证规则。我找不到如何去做的方法。

如何扩展网格弹出编辑器验证器的验证规则?

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");
    }
  }
});