EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: aswzen on June 30, 2014, 08:25:01 PM



Title: Remove text in combobox when no one match with the options
Post by: aswzen on June 30, 2014, 08:25:01 PM
Help me stworthy or anyone...

How to make the text that i write in combobox disappear when there are no options that match with the params?

demo to edit: http://jsfiddle.net/FrEHv/123/

thanks in advance......


Title: Re: Remove text in combobox when no one match with the options
Post by: stworthy on June 30, 2014, 11:55:04 PM
If you are sure that the value does not exist in the data list and you wish to clear the text box, please call 'setText' method with an empty string after calling 'setValue' method.
Code:
$('#Region').combobox('setValue', '5').combobox('setText','');

Another alternative way is to extend a new validation type to check if the value exists in the data list.
Code:
$.extend($.fn.validatebox.defaults.rules,{
       inList:{
              validator:function(value,param){
                     var c = $(param[0]);
                     var opts = c.combobox('options');
                     var data = c.combobox('getData');
                     var exists = false;
                     for(var i=0; i<data.length; i++){
                            if (value == data[i][opts.textField]){
                                   exists = true;
                                   break;
                            }
                     }
                     return exists;
              },
              message:'invalid value.'
       }
});
$(function(){
       $('#cc').combobox({
              required:true,
              validType:'inList["#cc"]'
       })
});



Title: Re: Remove text in combobox when no one match with the options
Post by: aswzen on August 28, 2014, 04:47:00 AM
hmm..not working...