diff options
-rw-r--r-- | extensions/BugModal/web/bug_modal.js | 18 | ||||
-rw-r--r-- | js/field.js | 19 |
2 files changed, 35 insertions, 2 deletions
diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index 38b19ac53..3d565e74f 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -325,7 +325,23 @@ $(function() { keywords = data.keywords; $('#keywords') .devbridgeAutocomplete({ - lookup: keywords, + lookup: function(query, done) { + query = query.toLowerCase(); + var matchStart = + $.grep(keywords, function(keyword) { + return keyword.toLowerCase().substr(0, query.length) === query; + }); + var matchSub = + $.grep(keywords, function(keyword) { + return keyword.toLowerCase().indexOf(query) !== -1 && + $.inArray(keyword, matchStart) === -1; + }); + var suggestions = + $.map($.merge(matchStart, matchSub), function(suggestion) { + return { value: suggestion }; + }); + done({ suggestions: suggestions }); + }, tabDisabled: true, delimiter: /,\s*/, minChars: 0, diff --git a/js/field.js b/js/field.js index d8ede471b..04633baaa 100644 --- a/js/field.js +++ b/js/field.js @@ -792,7 +792,24 @@ $(function() { .each(function() { var that = $(this); that.devbridgeAutocomplete({ - lookup: BUGZILLA.autocomplete_values[that.data('values')], + lookup: function(query, done) { + var values = BUGZILLA.autocomplete_values[that.data('values')]; + query = query.toLowerCase(); + var matchStart = + $.grep(values, function(value) { + return value.toLowerCase().substr(0, query.length) === query; + }); + var matchSub = + $.grep(values, function(value) { + return value.toLowerCase().indexOf(query) !== -1 && + $.inArray(value, matchStart) === -1; + }); + var suggestions = + $.map($.merge(matchStart, matchSub), function(suggestion) { + return { value: suggestion }; + }); + done({ suggestions: suggestions }); + }, tabDisabled: true, delimiter: /,\s*/, minChars: 0, |