Auto sort non-sortable multiselects

This commit is contained in:
claudiulodro 2017-08-18 11:35:12 -07:00
parent f0afd14ed3
commit 13acc510ef
8 changed files with 23 additions and 33 deletions

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -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

View File

@ -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