diff options
author | Go MAEDA <maeda@farend.jp> | 2020-12-25 02:31:55 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2020-12-25 02:31:55 +0000 |
commit | cde271e79e4c7ae1087797ffe1250f2d8aac6902 (patch) | |
tree | e371a3a0f1cd4271920fe39485e6d1507c598ad3 /public/javascripts/application.js | |
parent | 30e80d82ce189b4232e143b054f78870afd076da (diff) | |
download | redmine-cde271e79e4c7ae1087797ffe1250f2d8aac6902.tar.gz redmine-cde271e79e4c7ae1087797ffe1250f2d8aac6902.zip |
Allow issue relation autocomplete to select multiple values (#33418).
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@20690 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'public/javascripts/application.js')
-rw-r--r-- | public/javascripts/application.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/public/javascripts/application.js b/public/javascripts/application.js index c9b7d943d..98360fe70 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -617,6 +617,46 @@ function observeAutocompleteField(fieldId, url, options) { }); } +function multipleAutocompleteField(fieldId, url, options) { + function split(val) { + return val.split(/,\s*/); + } + + function extractLast(term) { + return split(term).pop(); + } + + $(document).ready(function () { + $('#' + fieldId).autocomplete($.extend({ + source: function (request, response) { + $.getJSON(url, { + term: extractLast(request.term) + }, response); + }, + minLength: 2, + position: {collision: "flipfit"}, + search: function () { + $('#' + fieldId).addClass('ajax-loading'); + }, + response: function () { + $('#' + fieldId).removeClass('ajax-loading'); + }, + select: function (event, ui) { + var terms = split(this.value); + // remove the current input + terms.pop(); + // add the selected item + terms.push(ui.item.value); + // add placeholder to get the comma-and-space at the end + terms.push(""); + this.value = terms.join(", "); + return false; + } + }, options)); + $('#' + fieldId).addClass('autocomplete'); + }); +} + function observeSearchfield(fieldId, targetId, url) { $('#'+fieldId).each(function() { var $this = $(this); |