django-select-multiple-field
django-select-multiple-field copied to clipboard
problems with keep order
somehow the returned order is the original order of the items, not the selected order
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
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]);
}
})
This is the working example:
https://stackoverflow.com/a/22271944/2068330