This is a migrated thread and some comments may be shown as answers.

How to display single validation message for a group of radio buttons in validation summary

1 Answer 1081 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Wesley
Top achievements
Rank 1
Wesley asked on 21 Dec 2020, 09:13 PM

Hi,

  I found a sample code to display one validation message for a group of radio buttons above the radio button group, but I am not able to display one message in validation summary.  Please try code snippet below.  You can see the validation message display 5 times in the summary.  I just want one message in summary.  Please help.

 

<div id="form">
    <span class="k-invalid-msg" data-for="test"></span><br/>
    Test 1<input type="radio" name="test" required /><br/>
    Test 1<input type="radio" name="test" required /><br/>
    Test 1<input type="radio" name="test" required /><br/>
    Test 1<input type="radio" name="test" required /><br/>
    Test 1<input type="radio" name="test" required /><br/>
    <button id="post">Post</button>
    
    <div id="step3-validation-summary">

     </div>
</div>

<script>
$(function(){
    var validator = $("#form").kendoValidator({
        rules: {
            radio: function(input) {
                if (input.filter("[type=radio]") && input.attr("required")) {
                    return $("#form").find("[type=radio][name=" + input.attr("name") + "]").is(":checked");
                }
                return true;
            }
        },
        messages: {
            radio: "This is a required field"
        },
        validationSummary: {
                container: "#step3-validation-summary"
            }
    }).getKendoValidator();

    $("#post").click(function() {
        validator.validate();
    });
});
</script>

 

Thanks,

Wesley

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 23 Dec 2020, 04:02 PM

Hello Wesley,

Achieving this would require using a validationSummary template and conditional logic in it: https://dojo.telerik.com/EGuQIBOJ/2

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Validation
Asked by
Wesley
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or