django-select-multiple-field icon indicating copy to clipboard operation
django-select-multiple-field copied to clipboard

problems with keep order

Open Hinnack opened this issue 9 years ago • 3 comments

somehow the returned order is the original order of the items, not the selected order

Hinnack avatar Oct 04 '15 19:10 Hinnack

see also: https://github.com/lou/multi-select/issues/184

so maybe include something like this into the widget: http://stackoverflow.com/questions/13243417/jquery-multiselect-selected-data-order

Hinnack avatar Oct 05 '15 09:10 Hinnack

so this is my solution:

          $(function () {
              $('#id_payment').multiSelect({ 
                  keepOrder: true,
                  afterSelect: function(value, text){
                    var get_val = $("#id_payment_val").val();
                    var hidden_val = (get_val != "") ? get_val+"," : get_val;
                    $("#id_payment_val").val(hidden_val+""+value);
                  },
                  afterDeselect: function(value, text){
                    var result = new Array();
                    var get_val = $("#id_payment_val").val().split(',');
                    for (var i=0; i<get_val.length; i++) {
                        if (get_val[i] != value) {
                            result.push(get_val[i]);
                        }
                    }
                    $("#id_payment_val").val(result.join(','));
                  }
              });
              var selected_val = $("#id_payment_val").val().split(',');
              $("#id_payment_val").val('');
              for (var q=0; q<selected_val.length; q++) {
                  $('#id_payment').multiSelect('select', selected_val[q]);
              }
          })

Hinnack avatar Oct 05 '15 09:10 Hinnack

This is the working example:

https://stackoverflow.com/a/22271944/2068330

AlsonicTech avatar Oct 26 '17 08:10 AlsonicTech