Auto sort non-sortable multiselects
This commit is contained in:
parent
f0afd14ed3
commit
13acc510ef
File diff suppressed because one or more lines are too long
|
@ -131,6 +131,24 @@ jQuery( function( $ ) {
|
|||
} );
|
||||
}
|
||||
});
|
||||
// Keep multiselects ordered alphabetically if they are not sortable.
|
||||
} else if ( $( this ).prop( 'multiple' ) ) {
|
||||
$( this ).on( 'change', function(){
|
||||
var $children = $( this ).children();
|
||||
$children.sort(function(a, b){
|
||||
var atext = a.text.toLowerCase();
|
||||
var btext = b.text.toLowerCase();
|
||||
|
||||
if (atext > btext) {
|
||||
return 1;
|
||||
}
|
||||
if (atext < btext) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
$( this ).html( $children );
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1689,20 +1689,6 @@ S2.define('select2/selection/multiple',[
|
|||
return;
|
||||
}
|
||||
|
||||
// Sort selected elements alphabetically by text.
|
||||
data.sort(function(a, b){
|
||||
atext = a.text.toLowerCase();
|
||||
btext = b.text.toLowerCase();
|
||||
|
||||
if (atext > btext) {
|
||||
return 1;
|
||||
}
|
||||
if (atext < btext) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
var $selections = [];
|
||||
|
||||
for (var d = 0; d < data.length; d++) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1689,20 +1689,6 @@ S2.define('select2/selection/multiple',[
|
|||
return;
|
||||
}
|
||||
|
||||
// Sort selected elements alphabetically by text.
|
||||
data.sort(function(a, b){
|
||||
atext = a.text.toLowerCase();
|
||||
btext = b.text.toLowerCase();
|
||||
|
||||
if (atext > btext) {
|
||||
return 1;
|
||||
}
|
||||
if (atext < btext) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
var $selections = [];
|
||||
|
||||
for (var d = 0; d < data.length; d++) {
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue