EasyUI Forum
April 28, 2024, 09:00:33 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: validatebox, adding a new rule  (Read 10637 times)
chrwei
Full Member
***
Posts: 219


View Profile Email
« on: August 22, 2013, 02:09:36 PM »

I'm looking for a cleaner way to do this:
Code:
<script>
$.extend($.fn.validatebox.defaults.rules, {
pickonemore: {
validator: function(value,param){
var hasone = false;
$(param).each(function(k,p) {
if ($(p).val() != "") hasone = true;
});
if(hasone) {
$(param).each(function(k,p) {
$(p).validatebox('disableValidation');
});
} else {
$(param).each(function(k,p) {
$(p).validatebox('enableValidation');
});
}
return hasone;
},
message: 'Enter at least one value in this group.'
}
});
</script>
<input id="box1" class="easyui-validatebox" type="text" name="box1" required="required" validType="pickonemore['#box1','#box2','#box3']"></input></td>
<input id="box2" class="easyui-validatebox" type="text" name="box2" required="required" validType="pickonemore['#box1','#box2','#box3']"></input></td>
<input id="box3" class="easyui-validatebox" type="text" name="box3" required="required" validType="pickonemore['#box1','#box2','#box3']"></input></td>

goal is to require one or more of the 3 values to be entered.  I'm using enableValidation/disableValidation calls because my new validator does not seemed to be called when a box is blank.  is there a better way?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: August 22, 2013, 07:06:54 PM »

After calling 'disableValidation' method, you need to call 'enableValidation' method again in some conditions. The simplest way to enable validation again is to recall 'enableValidation' method when value changed.
Code:
$('#box1,#box2,#box3').bind('keyup',function(){
$('#box1,#box2,#box3').validatebox('enableValidation').validatebox('validate');
});
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #2 on: August 23, 2013, 06:27:11 AM »

this is because if the value is selected and deleted, the validation won't fire since it doesn't run when the value is blank?  would it be a bad thing to run validation functions on blank values anyway?
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!