Skip to content

Commit

Permalink
Fix select ordering see #2224
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jmontoyaa committed Dec 13, 2017
1 parent bc54d39 commit 80aa54d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main/inc/lib/course.lib.php
Expand Up @@ -5984,7 +5984,8 @@ public static function buildSelectOptions(
$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
);
}
}
Expand Down
19 changes: 19 additions & 0 deletions main/inc/lib/javascript/pear/qfamsHandler.js
Expand Up @@ -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);
});
};

/**
Expand Down

0 comments on commit 80aa54d

Please sign in to comment.