EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on June 04, 2015, 04:44:23 AM



Title: Set icons conditionally by class [Solved]
Post by: devnull on June 04, 2015, 04:44:23 AM
How can I extend the textbox to set it's icons based on a specific class id, something like this:

Code:
  $.extend($.fn.textbox.defaults, {
    icons:function (jq){
     if($(this).hasClass('qbe')) return ([{
      iconCls:'icon-search',
      handler: function(e){
        $(e.data.target).textbox('setValue', 'Something added!');
      }
    }])
  }
})


Title: Re: Set icons conditionally by class
Post by: stworthy on June 04, 2015, 06:39:52 AM
The 'icons' is an array not a function. To create the 'icons' dynamically based on the class value, please override the $.fn.textbox.parseOptions function.
Code:
(function($){
    var parser = $.fn.textbox.parseOptions;
    $.fn.textbox.parseOptions = function(target){
        var opts = parser.call(this, target);
        if ($(target).hasClass('qbe')){
            opts.icons = [{
                iconCls: 'icon-search',
                handler: function(e){
                    $(e.data.target).textbox('setValue', 'Something added!');
                }
            }]
        }
        return opts;
    }
})(jQuery);


Title: Re: Set icons conditionally by class
Post by: devnull on June 04, 2015, 07:14:57 AM
Great Thanks so much :-)