Slaven Tomac
Slaven Tomac

Reputation: 1550

KendoUI grid minlength not working

can KendoUI grid enforce minlength validation. I have some troubles with it. Look at the screenshot.

I have set minlength and maxlength. It doesn't allow me to enter more than 10 letters, however, I can enter less than 2 letters and update the entry in grid.

Is this Kendo issue?

Developer Tools screenshot

Upvotes: 1

Views: 2956

Answers (1)

gitsitgo
gitsitgo

Reputation: 6769

As mentioned in my comments, minlength doesn't work because that attribute doesn't exist in HTML5 whereas maxlength does.

Instead, you have to use custom validation, or use the pattern attribute.

Pattern Attribute

my_name {
     validation: {
          required: true,
          pattern:'.{2,10}'
     }
},

This means that my_name must be between 2 to 10 characters. It will allow you to type less or more, but will throw invalid message when you try to update.

Custom Validation:

my_name {
     validation: {
          required: true,
          lengthRule: function (input) {
               if (input.is("[name='DirectionName']") && input.val() !== "") {
                    input.attr("data-lengthRule-msg", "My Name must be between 2 to 10 characters.");
                    return (input.val().length<=10 && input.val().length>=2);
               }
               return true;
          },
     }
},

With the latter method, there is a known bug, so I am not to keen on using the latter method.

Custom Valiation Bug FYI: Validation is not always triggered when editing with backspace

Upvotes: 3

Related Questions