diff --git a/app/assets/javascripts/discourse/lib/autocomplete.js b/app/assets/javascripts/discourse/lib/autocomplete.js index 357438192f9..b89d9a6ef21 100644 --- a/app/assets/javascripts/discourse/lib/autocomplete.js +++ b/app/assets/javascripts/discourse/lib/autocomplete.js @@ -89,7 +89,7 @@ $.fn.autocomplete = function(options) { if (options.transformComplete) { transformedItem = options.transformComplete(transformedItem); } // dump what we have in single mode, just in case if (options.single) { inputSelectedItems = []; } - if (!_.isArray(transformedItem)) { transformed = [transformedItem || item]; } + transformed = _.isArray(transformedItem) ? transformedItem : [transformedItem || item]; var divs = transformed.map(function(itm) { var d = $("
"); diff --git a/app/assets/javascripts/discourse/views/user_selector_view.js b/app/assets/javascripts/discourse/views/user_selector_view.js index 28e67650a73..9cb4a7bc7ee 100644 --- a/app/assets/javascripts/discourse/views/user_selector_view.js +++ b/app/assets/javascripts/discourse/views/user_selector_view.js @@ -4,6 +4,14 @@ Discourse.UserSelector = Discourse.TextField.extend({ var userSelectorView = this, selected = []; + function excludedUsernames() { + var exclude = selected; + if (userSelectorView.get('excludeCurrentUser')) { + exclude = exclude.concat([Discourse.User.currentProp('username')]); + } + return exclude; + } + $(this.get('element')).val(this.get('usernames')).autocomplete({ template: Discourse.UserSelector.templateFunction(), @@ -12,14 +20,10 @@ Discourse.UserSelector = Discourse.TextField.extend({ allowAny: this.get('allowAny'), dataSource: function(term) { - var exclude = selected; - if (userSelectorView.get('excludeCurrentUser')) { - exclude = exclude.concat([Discourse.User.currentProp('username')]); - } return Discourse.UserSearch.search({ term: term, topicId: userSelectorView.get('topicId'), - exclude: exclude, + exclude: excludedUsernames(), include_groups: userSelectorView.get('include_groups') }); }, @@ -28,7 +32,11 @@ Discourse.UserSelector = Discourse.TextField.extend({ if (v.username) { return v.username; } else { - return v.usernames; + var excludes = excludedUsernames(); + return v.usernames.filter(function(item){ + // include only, those not found in the exclude list + return excludes.indexOf(item) === -1; + }); } },