Skip to content

Instantly share code, notes, and snippets.

@06b
Created November 6, 2015 20:34
Show Gist options
  • Save 06b/4176ed74a6fa6920b5be to your computer and use it in GitHub Desktop.
Save 06b/4176ed74a6fa6920b5be to your computer and use it in GitHub Desktop.
Kendo DropDown Validation Fix for Error Styling
//kendo validation is required for validation of kendo controls to work properly.
$("form").kendoValidator({
errorTemplate: "", //remove the additions kendo places to the right of each field.
validate: function (e) {
//Bizarrely, Kendo dropdowns require special attention.
//Span with k-dropdown are kendo dropdown controls. They contain an input, which is used to store the value,
//and another span (which has .k-input-wrap) that controls the actual presentation.
//
//The problem is that k-invalid is placed on the input, which isn't even visible. So, we have to
//check the input for .k-invalid, and set a class on the span to control validation appearance.
var dropDowns = $(".k-dropdown");
$.each(dropDowns, function (key, value) {
var input = $(value).find("input.k-invalid"); //this is where Kendo foolishly places k-invalid
var span = $(this).find("span.k-dropdown-wrap"); //this span controls the dropdown's appearance.
//manually set the validation attributes.
if (input.size() > 0) { //if there is an input in here with k-invalid...
$(span).addClass("k-invalid");
} else {
$(span).removeClass("k-invalid");
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment