EasyUI Forum

General Category => General Discussion => Topic started by: john17 on July 13, 2014, 11:37:34 PM



Title: create validation when check box is check
Post by: john17 on July 13, 2014, 11:37:34 PM
hi guys,

is it possible to create a validation on validatebox when check box is checked?if yes how?

thanks


Title: Re: create validation when check box is check
Post by: stworthy on July 14, 2014, 02:27:20 AM
To validate a checkbox field, you have to extend a new validate rule and apply it to this field.
Code:
$.extend($.fn.validatebox.defaults.rules,{
checked: {
validator:function(value,param){
var c = $(param[0]);
if (!c[0]._binded){
c[0]._binded = true;
c.unbind('.cc').bind('change.cc',function(){
c.validatebox('validate');
})
}
return c.is(':checked');
},
message:'Please check it.'
}
})

Apply this 'checked' rule to an existing field.
Code:
<input id="cc" type="checkbox" name="n1" class="easyui-validatebox" 
data-options="required:true,validType:'checked[\'#cc\']'">


Title: Re: create validation when check box is check
Post by: john17 on July 15, 2014, 01:21:44 AM
thank you very much for your reply  ;D