Extending the Kendo UI validator to support required validation on radio buttons

2 posts, 0 answers
  1. Trent
    Trent avatar
    4 posts
    Member since:
    Dec 2011

    Posted 24 Jan 2014 Link to this post

    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?
  2. Alexander Popov
    Alexander Popov avatar
    1411 posts

    Posted 28 Jan 2014 Link to this post

    Hello Trent,

    Thank you for your feedback!
    The main reasons for not including a built-in radio button validation are exactly the ones you mentioned - performance and the necessity of adding the required attribute to each element in the radio button group. I would encourage you to submit this as a feature request at KendoUI UserVoice so we and other members of the community can evaluate, comment on and vote for it. Most voted requests are often included in future KendoUI releases.

    Alexander Popov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top