Fanda
Fanda

Reputation: 3786

How to configure custom validation rules for kendo grid editor

We have ASP.NET MVC application using Telerik UI for ASP.NET MVC. On the page is set up a grid with popup editor, by kendo html helper.

Now I need to configure some custom validation rules for popup editor form. I can't find a way how to do it.

How can extend validation rules of the grid popup editor validator?

Upvotes: 1

Views: 2719

Answers (1)

Boric
Boric

Reputation: 872

Kendo widgets built with an HTML helper, such as the Grid, 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 of how to do this:

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

Upvotes: 1

Related Questions