lou / multi-select

A user-friendlier drop-in replacement for the standard select with multiple attribute activated.
loudev.com
MIT License
1.9k stars 439 forks source link

keepOrder does not keep order on underlying SELECT: FIX in the post #105

Open iztisnitibe opened 10 years ago

iztisnitibe commented 10 years ago

the order on the underlying SELECT is not kept.

changing this if in the 'select' part solves the problem

      if (that.options.keepOrder){
        var selectionLiLast = that.$selectionUl.find('.ms-selected'); 
        if((selectionLiLast.length > 1) && (selectionLiLast.last().get(0) != selections.get(0))) {
        // added the if MZI: it's needed for the init where multiple values might be selected already in correct order
            if( 1 == options.length ){
          selections.insertAfter(selectionLiLast.last());
          }            }
        // added by MZI: reorders the underlying SELECT
          var ol = ms[0].options[(ms[0].options.length)-1];
          options.insertAfter(ol);
      }
ghost commented 10 years ago

I think your code has a little problem. I have changed your code to following code, and it worked well.

if (method !== 'init'){ var ol = ms[0].options[(ms[0].options.length)-1]; options.insertAfter(ol); }

If there is any problem, let me know. Thanks

razlupercio commented 9 years ago

I have a similar problem and I resolved it using an stackoverflow answer but can´t find the question, here is my code:

afterSelect: function(value)

   {
         $('#select option[value="'+value+'"]').remove();
         $('#select').append($("<option></option>").attr("value",value).attr('selected', 'selected'));
         var options= $('#select').val().toString();
        // DO SOMETHING WITH THE OPTIONS
     },

    afterDeselect: function(value)

    {
         $('#select option[value="'+value+'"]').removeAttr('selected');
          var options= $('#select ').val().toString();
           // DO SOMETHING WITH THE OPTIONS

     }

In my particular case I just needed to send a string with the options ordered by the user, but I guess you can send also an array. Good luck & happy coding!

lougmani commented 3 years ago

var ol = ms[0].options[(ms[0].options.length)-1]; options.insertAfter(ol);

It solves the issue. but limit selection not working