diff --git a/app/assets/javascripts/discourse/components/autocomplete.js b/app/assets/javascripts/discourse/components/autocomplete.js index d4d7ecc0a62..10a5f2d0f5f 100644 --- a/app/assets/javascripts/discourse/components/autocomplete.js +++ b/app/assets/javascripts/discourse/components/autocomplete.js @@ -203,18 +203,8 @@ $.fn.autocomplete = function(options) { closeAutocomplete(); }); - $(this).keypress(function(e) { - if(options.allowAny){ - if(inputSelectedItems.length === 0) { - inputSelectedItems.push(""); - } - inputSelectedItems.pop(); - inputSelectedItems.push(me.val()); - if (options.onChangeItems) { - options.onChangeItems(inputSelectedItems); - } - } + $(this).keypress(function(e) { if (!options.key) return; @@ -232,6 +222,25 @@ $.fn.autocomplete = function(options) { return $(this).keydown(function(e) { var c, caretPosition, i, initial, next, nextIsGood, prev, prevIsGood, stopFound, term, total, userToComplete; + + if(options.allowAny){ + // saves us wiring up a change event as well, keypress is while its pressed + _.delay(function(){ + if(inputSelectedItems.length === 0) { + inputSelectedItems.push(""); + } + + if(_.isString(inputSelectedItems[0])) { + inputSelectedItems.pop(); + inputSelectedItems.push(me.val()); + if (options.onChangeItems) { + options.onChangeItems(inputSelectedItems); + } + } + + },50); + } + if (!options.key) { completeStart = 0; }