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

is there other easy way to reserve selected order #61

Open
openxyz opened this issue Mar 14, 2013 · 8 comments
Open

is there other easy way to reserve selected order #61

openxyz opened this issue Mar 14, 2013 · 8 comments
Labels

Comments

@openxyz
Copy link

openxyz commented Mar 14, 2013

not only i want konw which items were seleced,,but also what order these selected items was..

so i do it as below , Is there other easy way ?

$(document).on("submit", "form", function(event){
    var mselect = $('#myselect');
    var ms = $('#ms-myselect');
    var ids = $.map(ms.find('.ms-selection li[ms-value]'),function(e){return $(e).attr('ms-value')})

    mselect.append(mselect.find("option").remove().sort(function(a, b) {
      return ids.indexOf($(a).val()) > ids.indexOf($(b).val());
    }));
  });
@ridiculous
Copy link

Yes, the plugin has an afterSelect callback that should do what you want. I've used something like this:

var master_list = [];
$('#myselect').multiSelect({
    afterSelect: function (value) {
        for (var i = 0; i < value.length; i++)  master_list.push(value[i]);
    }
})

The value parameter given to the callback is an array with whatever the value is for your select options. If its an id, then it look like ["1"]. I used a loop because I am not sure if it will always be a single item array. You could alternatively just use master_list.push(value[0]). Either way, master_list will have the items in the order they were selected. FYI, there is also an afterDeselect callback.

Hope that helps!

@openxyz
Copy link
Author

openxyz commented Mar 14, 2013

thank very much. more question:
i use v0.8 in above code ,so i can get order with keepOrder : false,
but i find there no keepOrder options when i change to latest v0.9 5,, :(

@ridiculous
Copy link

Hmm not sure about that. But you can probably do without it

@lou
Copy link
Owner

lou commented Mar 14, 2013

hi @openxyz,
Unfortunately, you are right! I removed the keepOrder option on 0.9+.
I rewrote the init method of the plugin and since selected items are now in the same order than the selectable ones by default I decided not to re-introduce the keepOrder option.
It was obviously a mistake and I will add it to the roadmap.

@jvosloo
Copy link

jvosloo commented May 9, 2013

The keepOrder property will be really useful for me. Any eta on when it might be available?

@lou
Copy link
Owner

lou commented May 14, 2013

Hi @jvosloo,

I'm sorry I do not have any ETA for the moment since I'm in a middle of a long offline vacations.

I thought about this issue and it's not an easy one since I have to handle this feature when optgroups are present too.
If you are not using optgroups you could just delete and prepend the selected items on the selection list on the afterSelect callback.

@lou
Copy link
Owner

lou commented Jul 3, 2013

the keepOrder is back with this commit 73191d5

Please note that it won't work if there are <optgroup> in the original <select>. I do not know if it should, so in doubt I did the simplest thing to do. So let me know.

@IchigoWalker
Copy link

try this #221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants