Is there a particular reason the Kendo UI validator does not support required radio button validation out of the box? Adding basic validation to the existing required rule seems relatively straightforward.
var radio = input.filter("[type=radio]");
if (radio.length) {
//Ideally the search should be scoped to the element that validate was called on, but that would require several other changes
return $("input[name='" + input.attr("name") + "']").is(":checked");
}
This would enable radio button validation, but would require all radio buttons in a group to specify the required attribute or the other radio buttons in the group would validate successfully, overriding the one that failed. A solution to the problem would be to do what jQuery validate does, which is to only validate the first element in an array of elements with the same name. Is there any downside to doing this? The only common uses for elements with the same name are checkboxes, radio buttons and buttons, and since buttons are already not validated, I don't see any downside.
Right now, without making the code changes specified above, I am relying on a custom rule that is incredibly inefficient since it has to continually get all radio buttons with the same name to see if any of them are decorated with a required attribute.
radiorequired: function (input) {
if (input.is("[type=radio]")) {
var radioButtons = $("input[name='" + input.attr("name") + "']");
if (!radioButtons.is("[data-val-required], required")) return true;
return radioButtons.is(":checked");
}
return true;
}
I guess my question is, why doesn't Kendo UI support required validation on radio buttons out of the box, and is there a better way to add the validation than what I am doing now?
var radio = input.filter("[type=radio]");
if (radio.length) {
//Ideally the search should be scoped to the element that validate was called on, but that would require several other changes
return $("input[name='" + input.attr("name") + "']").is(":checked");
}
This would enable radio button validation, but would require all radio buttons in a group to specify the required attribute or the other radio buttons in the group would validate successfully, overriding the one that failed. A solution to the problem would be to do what jQuery validate does, which is to only validate the first element in an array of elements with the same name. Is there any downside to doing this? The only common uses for elements with the same name are checkboxes, radio buttons and buttons, and since buttons are already not validated, I don't see any downside.
Right now, without making the code changes specified above, I am relying on a custom rule that is incredibly inefficient since it has to continually get all radio buttons with the same name to see if any of them are decorated with a required attribute.
radiorequired: function (input) {
if (input.is("[type=radio]")) {
var radioButtons = $("input[name='" + input.attr("name") + "']");
if (!radioButtons.is("[data-val-required], required")) return true;
return radioButtons.is(":checked");
}
return true;
}
I guess my question is, why doesn't Kendo UI support required validation on radio buttons out of the box, and is there a better way to add the validation than what I am doing now?