Is it possible to sort by full name in user list selection for survey permission?
For example from this picture:
Default is order by username.
In this case username is' limesurv' and full mane is 'administrator'
2) Insert something like this into the custom JavaScript file. It will sort the list options by their strings split at the first space.
Code:
$(document).ready(function(){
// Sort the user list in "Survey permissions"
if($('#uidselect').length > 0) {
var userList = $('#uidselect');
var userOptions = $('option', userList);
var selectedOption = $(userList).val();
// Case insensitive sort
// Options sorted by string split at the first space
/*
userOptions.sort(function(a,b) {
if (a.text.replace(/^([^\s]+)\s(.+)$/,"$2 $1").toLowerCase() > b.text.replace(/^([^\s]+)\s(.+)$/,"$2 $1").toLowerCase()) return 1;
if (a.text.replace(/^([^\s]+)\s(.+)$/,"$2 $1").toLowerCase() < b.text.replace(/^([^\s]+)\s(.+)$/,"$2 $1").toLowerCase()) return -1;
return 0
});
*/
// Case sensitive sort
// Options sorted by string split at the first space
userOptions.sort(function(a,b) {
if (a.text.replace(/^([^\s]+)\s(.+)$/,"$2 $1") > b.text.replace(/^([^\s]+)\s(.+)$/,"$2 $1")) return 1;
if (a.text.replace(/^([^\s]+)\s(.+)$/,"$2 $1") < b.text.replace(/^([^\s]+)\s(.+)$/,"$2 $1")) return -1;
return 0
});
$(userList).empty().append(userOptions);
$(userList).prepend($('option[value="-1"]', userList));
$(userList).val(selectedOption);
}
});
Cheers,
Tony Partner Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.