From 80aa54d5839e6ce649c895378a96ec9b958881b5 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 13 Dec 2017 16:04:18 +0100 Subject: [PATCH] Fix select ordering see #2224 The space before "G" in the option value is needed in order to advmultiselect.php js puts the group items first so: So it will appear like this: G: group 1 Aimee Mann Bob Instead of: Aimee Mann Bob G: group 1 --- main/inc/lib/course.lib.php | 3 ++- main/inc/lib/javascript/pear/qfamsHandler.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 888182e714..669d2636dd 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -5984,7 +5984,8 @@ class CourseManager $result[] = array( 'disabled' => $user_disabled, 'value' => "GROUP:".$this_group['id'], - 'content' => "G: ".$this_group['name']." - ".$this_group['userNb']." ".$user_label + // The space before "G" is needed in order to advmultiselect.php js puts groups first + 'content' => " G: ".$this_group['name']." - ".$this_group['userNb']." ".$user_label ); } } diff --git a/main/inc/lib/javascript/pear/qfamsHandler.js b/main/inc/lib/javascript/pear/qfamsHandler.js index 4c264dfaef..9e579eab54 100755 --- a/main/inc/lib/javascript/pear/qfamsHandler.js +++ b/main/inc/lib/javascript/pear/qfamsHandler.js @@ -270,6 +270,25 @@ QFAMS.moveSelection = function (qfamsName, selectLeft, selectRight, selectHidden // Set the appropriate items as 'selected in the hidden select. // These are the values that will actually be posted with the form. QFAMS.updateHidden(selectHidden, selectRight); + + // Order alphabetically + + //var sourceId = $(source).attr('id'); + var targetId = $(target).attr('id'); + var options = $('#' + targetId +' option'); + + var arr = options.map(function(_, o) { return { t: $(o).text(), v: o.value }; }).get(); + arr.sort(function (o1, o2) { + //return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0; + // Ignore case + var t1 = o1.t.toLowerCase(), t2 = o2.t.toLowerCase(); + return t1 > t2 ? 1 : t1 < t2 ? -1 : 0; + }); + + options.each(function(i, o) { + o.value = arr[i].v; + $(o).text(arr[i].t); + }); }; /**