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

How can I validate the input type="radio"

4 Answers 1013 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Wichit
Top achievements
Rank 1
Wichit asked on 08 May 2012, 01:34 PM
I'm newbie ,Help me please. How can I validate the input type="radio"? 
My code is : 
<input id="connectionType" name="connection" type="radio" value="1" required validationMessage='<spring:message code="ui.customer.create.require.connection"/>' />
<spring:message code="ui.customer.create.lable.connection.new"/>

<input id="connectionType" name="connection" type="radio" value="2" required validationMessage='<spring:message code="ui.customer.create.require.connection"/>'/>
<spring:message code="ui.customer.create.lable.connection.exist"/>

and javascript is : 
$("#save").click(function(){
      
    var validatable = $("#create_window").kendoValidator().data("kendoValidator");
    if (validatable.validate()) {
    ajaxSubmitFormSimple($('#create_window'),'createCustomer.do',$('#createCustomerForm').serialize());
    }
    return false;
});

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 10 May 2012, 09:24 AM
Hi Wichit,

You should register a custom validation rule to validate the radio buttons as shown in the following jsFiddle:

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Aaron
Top achievements
Rank 1
answered on 19 Oct 2012, 07:19 PM

I ran into this as well. The snippet provided is almost right, but it goofs up other validations you might have setup.

What appears to work for me is:

rules: {
           radio: function(input) {
               if (input.is("[type=radio]") && input.attr("required")) {        
                  return $("#newStatusOverride").find("[name=" + input.attr("name") + "]").is(":checked");
               }
               return true;
            }
           },
           messages: {
               radio: "Please select a status"
           }

The difference being changing the .filter to .is

0
yamaha
Top achievements
Rank 1
answered on 16 Oct 2015, 12:35 PM

I know this is an old post but thought it was worth try asking. My requirement is there are set of 2 radio buttons and only one of them can be selected. I have given them same 'name' and that functionality works. I have a custom rule defined which checks to see if "Physician" radio button is checked then we validate that a "Speciality" from the specialty dropdown has been selected.

The problem I am running into is that when I check Physician radio button and do not select a Specialty I get an error pop-up which is blank. No error message. I have around 15 other custom validation on same page which form flawlessly. 

Here is link to my code. http://jsfiddle.net/tpBEb/76/

 Do you see anything wrong with the way I have written my html or custom validator rule ?

Thanks!

0
Daniel
Telerik team
answered on 21 Oct 2015, 11:33 AM
Hello,

The code looks correct. I updated the example to bind a sample ViewModel to the form and the message is shown correctly. Please check the example and let me know if I am missing something. 

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Validation
Asked by
Wichit
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Aaron
Top achievements
Rank 1
yamaha
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or