styopdev/multiPicker

Select all / Unselect all

DeMoehn opened this issue · 2 comments

Hey,

I'm using Lists with the multiPicker.
Everything worked fine unless I started to implement an edit-function within my application.
I tried to auto-select the Options (li items) with the prePopulate option. $("#alarmdays").multiPicker({ selector : "li", prePopulate : data.data.days });
Works ok for me, but when some of the Elements are already active, they'll be unselected by this function, also it doesn't clear the past selection so I may end up with a mess.

I could not find a simple "Unselect()" function in the documentation.
My workaround right now is to delete the value of the hidden field and remove the "active" classes from the options by:

    $('input[name=alarmdays]').val('');
    $("#alarmdays").children().removeClass('active');

If there already are functions like this, im sorry.
Otherwise it would be a great improvement.

EDIT:

Actually the "prePopulate" doesn't work for me, as I can't change the selection afterwards.
I created these two handy helper functions:

  // -- Helper to unselect a list
  function unselect(list) {
    $('input[name='+list+']').val('');
    $("#"+list).children().removeClass('active');
  }

  // -- Helper to select options in a list
  function select(list, elements) {
    $("#"+list+" li").each(function( index ) {
      if($.inArray( index, elements ) >= 0) {
        $( this ).click();
      }
    });
  }

Hi @DeMoehn, Thanks for message.

Currently I am working on methods you would like to use. There are several improvements and testing I need to do, before merge it with master.

Full list of methods you can find here.

API methods finished, well tested and available on master. Also I have updated the docs. Let me know if there is something else.