Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select all / Unselect all #12

Closed
DeMoehn opened this issue Sep 19, 2016 · 2 comments
Closed

Select all / Unselect all #12

DeMoehn opened this issue Sep 19, 2016 · 2 comments

Comments

@DeMoehn
Copy link

DeMoehn commented Sep 19, 2016

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();
      }
    });
  }
@styopdev
Copy link
Owner

styopdev commented Sep 19, 2016

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.

@styopdev
Copy link
Owner

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

@styopdev styopdev closed this as completed Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants