EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: varonica on December 26, 2012, 01:27:40 AM



Title: validate rule: 'remote'
Post by: varonica on December 26, 2012, 01:27:40 AM
Hi sir, im trying to do as following code:
Code:
<input class="easyui-combobox" validType="remote['get_data.php','paramName']" />

Code:
//get_data.php
<?php 
$param intval($_REQUEST['paramName']);
if($param 10){
echo 'true';
}else{
echo 'false';
}


?>

No luck, it works perfectly but every time we click or writing one word in the textbox, it sends request out. Can it send a request after users finish writing or ".focusout()" ???  ??? ???


Title: Re: validate rule: 'remote'
Post by: stworthy on December 26, 2012, 06:59:23 PM
To validate when inputs lose focus, try the code below.
Code:
$(function(){
$('#nn').bind('focus',function(){
$(this).data('validatebox').validating = false;
}).bind('blur',function(){
$(this).validatebox('validate');
});
});

Another way is to delay validating from the last inputting value, this feature will be supported in next version(1.3.2). This plugin can be downloaded from http://www.jeasyui.com/easyui/plugins/jquery.validatebox.js. To use the delay validating, assign the validatebox with a delay value.

Code:
<input class="easyui-combobox" delay="500" validType="remote['get_data.php','paramName']" />


Title: Re: validate rule: 'remote'
Post by: varonica on December 27, 2012, 12:29:44 AM
Code:
$(function(){
$('#nn').bind('focus',function(){
$(this).data('validatebox').validating = false;
}).bind('blur',function(){
$(this).validatebox('validate');
});
});
Hi sir, the above code seem not working correctly without putting "required" property. And here is what i messed up so far and hope u don't mind:
Code:
$.extend($.fn.validatebox.defaults.rules, {  
    check: { 
validator: function(value,param){ 
    var obj = $(param[0]).combobox('getData');
    var arr = [];
    arr = $.map(obj,function(n,i){
        var n = n.name1 || n.name2 ;
        return n;
    });
    var result = jQuery.inArray(value, arr);
    if(result == -1) return false;
    else return true;
          }, 
             message: 'Incorrect!' 
       } 
});


Title: Re: validate rule: 'remote'
Post by: stworthy on December 27, 2012, 02:17:10 AM
Please refer to this example http://jsfiddle.net/AmEt6/.


Title: Re: validate rule: 'remote'
Post by: varonica on December 28, 2012, 01:21:06 AM
Hi sir, here is what i was trying: http://jsfiddle.net/p9LdJ/ . I just want to validate a combobox using .focusout() event( Everytime we focusout then let it validate the combobox )


Title: Re: validate rule: 'remote'
Post by: stworthy on December 28, 2012, 01:39:47 AM
The alternate solution is to set a big delay value to prevent from validating when get focus. Please refer to updated example http://jsfiddle.net/p9LdJ/1/. To apply the 'delay' property on validatebox, please download the updated validatebox plugin from http://www.jeasyui.com/easyui/plugins/jquery.validatebox.js. This property will be supported since version 1.3.2.


Title: Re: validate rule: 'remote'
Post by: varonica on December 28, 2012, 03:32:42 AM
Thank sir for helping me!! :) :) ;)