Reputation: 1550
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?
Upvotes: 1
Views: 2956
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