- Posts: 16
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
$(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); } });