FIX: Category autocomplete breaks when search menu widget rerenders.

https://github.com/discourse/discourse/pull/4717#issuecomment-284914585
This commit is contained in:
Guo Xiang Tan 2017-03-08 20:13:22 +08:00
parent 3c41cb6b7d
commit 6a7773b681
3 changed files with 14 additions and 7 deletions

View File

@ -261,7 +261,11 @@ export default function(options) {
left: "-1000px"
});
me.parent().append(div);
if (options.appendSelector) {
me.parents(options.appendSelector).append(div);
} else {
me.parent().append(div);
}
if (!isInput && !options.treatAsTextarea) {
vOffset = div.height();

View File

@ -130,14 +130,14 @@ export function isValidSearchTerm(searchTerm) {
}
};
export function applySearchAutocomplete($input, siteSettings, appEvents) {
export function applySearchAutocomplete($input, siteSettings, appEvents, options) {
const afterComplete = function() {
if (appEvents) {
appEvents.trigger("search-autocomplete:after-complete");
}
};
$input.autocomplete({
$input.autocomplete(_.merge({
template: findRawTemplate('category-tag-autocomplete'),
key: '#',
width: '100%',
@ -153,9 +153,9 @@ export function applySearchAutocomplete($input, siteSettings, appEvents) {
return searchCategoryTag(term, siteSettings);
},
afterComplete
});
}, options));
$input.autocomplete({
$input.autocomplete(_.merge({
template: findRawTemplate('user-selector-autocomplete'),
key: "@",
width: '100%',
@ -163,5 +163,5 @@ export function applySearchAutocomplete($input, siteSettings, appEvents) {
transformComplete: v => v.username || v.name,
dataSource: term => userSearch({ term, includeGroups: true }),
afterComplete
});
}, options));
};

View File

@ -262,7 +262,10 @@ export default createWidget('header', {
Ember.run.schedule('afterRender', () => {
const $searchInput = $('#search-term');
$searchInput.focus().select();
applySearchAutocomplete($searchInput, this.siteSettings, this.appEvents);
applySearchAutocomplete($searchInput, this.siteSettings, this.appEvents, {
appendSelector: '.menu-panel'
});
});
}
},