multi-select icon indicating copy to clipboard operation
multi-select copied to clipboard

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

Open iztisnitibe opened this issue 12 years ago • 3 comments

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);
      }

iztisnitibe avatar Oct 29 '13 18:10 iztisnitibe

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

ghost avatar Mar 15 '14 01:03 ghost

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!

razlupercio avatar Apr 01 '15 19:04 razlupercio

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

It solves the issue. but limit selection not working

lougmani avatar Oct 11 '21 02:10 lougmani