EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: varonica on July 25, 2014, 02:16:25 AM



Title: checkbox in Multiple Select of combobox
Post by: varonica on July 25, 2014, 02:16:25 AM
Hi, i wonder if we can add checkbox to combobox(Multiple Select) . Is there a way to do that ?


Title: Re: checkbox in Multiple Select of combobox
Post by: stworthy on July 25, 2014, 09:04:00 AM
Set 'multiple' property to true and the user can select multiple items from combobox. If you really want to add checkbox to every item, please use 'formatter' function to customize the item. Here is the simple implementation to display item checkbox.
Code:
$('#cc').combobox({
  formatter:function(row){
    var opts = $(this).combobox('options');
    return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]
  },
  onLoadSuccess:function(){
    var opts = $(this).combobox('options');
    var target = this;
    var values = $(target).combobox('getValues');
    $.map(values, function(value){
      var el = opts.finder.getEl(target, value);
      el.find('input.combobox-checkbox')._propAttr('checked', true);
    })
  },
  onSelect:function(row){
    console.log(row)
    var opts = $(this).combobox('options');
    var el = opts.finder.getEl(this, row[opts.valueField]);
    el.find('input.combobox-checkbox')._propAttr('checked', true);
  },
  onUnselect:function(row){
    var opts = $(this).combobox('options');
    var el = opts.finder.getEl(this, row[opts.valueField]);
    el.find('input.combobox-checkbox')._propAttr('checked', false);
  }
})


Title: Re: checkbox in Multiple Select of combobox
Post by: varonica on July 25, 2014, 06:56:29 PM
Thanks, you're a genius!!  :'( :'( :'( :'( :-* :-* :-* :-* :-* :-[ :-[ :-[ 8) 8) 8) 8) :D :D :D :D :D :D ;) ;) ;)


Title: Re: checkbox in Multiple Select of combobox
Post by: arma on August 05, 2014, 06:25:56 AM
Hi,

I could not get the onSelect to work. Error on this line :

var el = opts.finder.getEl(this, row[opts.valueField]);

Uncaught TypeError: Cannot read property 'getEl' of undefined. I tried to console.log(opts) but it seems there's no object finder.

Thanks