Commit 27f4f2ef authored by Clement Ho's avatar Clement Ho

[skip ci] add support for limiting assignee selection

parent 22af8970
...@@ -299,6 +299,22 @@ import eventHub from './sidebar/event_hub'; ...@@ -299,6 +299,22 @@ import eventHub from './sidebar/event_hub';
const previouslySelected = $dropdown.closest('.selectbox') const previouslySelected = $dropdown.closest('.selectbox')
.find("input[name='" + ($dropdown.data('field-name')) + "'][value!=0]"); .find("input[name='" + ($dropdown.data('field-name')) + "'][value!=0]");
// Enables support for limiting the number of users selected
// Automatically removes the first on the list if more users are selected
const maxSelect = $dropdown.data('max-select');
if (maxSelect) {
const selected = getSelected();
if (selected.length > maxSelect) {
const firstSelectedId = selected[0];
const firstSelected = $dropdown.closest('.selectbox')
.find(`input[name='${$dropdown.data('field-name')}'][value=${firstSelectedId}]`);
firstSelected.remove();
eventHub.$emit('sidebar.removeUser', firstSelectedId);
}
}
if (user.beforeDivider && user.name.toLowerCase() === 'unassigned') { if (user.beforeDivider && user.name.toLowerCase() === 'unassigned') {
// Unassigned selected // Unassigned selected
previouslySelected.each((index, element) => { previouslySelected.each((index, element) => {
......
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
- options[:toggle_class] += ' js-multiselect js-save-user-data' - options[:toggle_class] += ' js-multiselect js-save-user-data'
- options[:data][:field_name] = "#{issuable.to_ability_name}[assignee_ids][]" - options[:data][:field_name] = "#{issuable.to_ability_name}[assignee_ids][]"
- options[:data][:multi_select] = true - options[:data][:multi_select] = true
- options[:data]['dropdown-title'] = 'Select assignee(s)' - options[:data]['dropdown-title'] = title
- options[:data]['dropdown-header'] = 'Assignee(s)' - options[:data]['dropdown-header'] = 'Assignee(s)'
- else - else
- title = 'Select assignee' - title = 'Select assignee'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment