EasyUI Forum
April 29, 2024, 08:12:09 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: required radiobuttons in a form  (Read 23507 times)
rumbleDom
Newbie
*
Posts: 2


View Profile
« on: January 10, 2013, 09:45:21 AM »

Hello ...
if I need a radio from a user in a form, how can I do that?
This code is not working :-(
Code:
<input type="Radio" name="Gender" value="1" checked="checked" class="easyui-validatebox" required="true">
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: January 10, 2013, 06:31:21 PM »

If you want to validate if a field is selected. Use the checkbox field instead. The validation on a checkbox field is not supported directly but extending a new validator is possible.
Code:
$.extend($.fn.validatebox.defaults.rules, {  
checked: { 
validator: function(value, param){ 
var input = $(param[0]);
input.unbind('.cc').bind('click.cc',function(){
$(this).focus();
});
return input.is(':checked'); 
}, 
message: 'Please check this field.' 

});
Code:
<input id="gg" type="checkbox" name="Gender" value="1" checked="checked" class="easyui-validatebox" validType="checked['#gg']">
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #2 on: September 18, 2013, 08:00:16 AM »

I have made a validator for radio buttons.

Code:
	$.extend($.fn.validatebox.defaults.rules, {
requireRadio: { 
validator: function(value, param){ 
var input = $(param[0]);
input.off('.requireRadio').on('click.requireRadio',function(){
$(this).focus();
});
return $(param[0] + ':checked').val() != undefined;
}, 
message: 'Please choose option for {1}.' 

});

it used by adding it to only the first radio in a group.  adding to all is no harm, it just wastes CPU.
Code:
<input class="easyui-validatebox" type="radio" name="yes_no" value="1" data-options="validType:'requireRadio[\'#ff input[name=yes_no]\', \'Yes or no\']'">Yes

<input class="easyui-validatebox" type="radio" name="yes_no" value="0">No
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!