Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Autocomplete/assets/dist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,12 @@ function _createAutocompleteWithRemoteData(autocompleteEndpointUrl, minCharacter
},
load: function(query, callback) {
const url = this.getUrl(query);
const dropdown = this.dropdown_content;
const scroll = dropdown ? dropdown.scrollTop : 0;
fetch(url).then((response) => response.json()).then((json) => {
this.setNextUrl(query, json.next_page);
callback(json.results.options || json.results, json.results.optgroups || []);
if (dropdown) dropdown.scrollTop = scroll;
}).catch(() => callback([], []));
},
shouldLoad: (query) => {
Expand Down
5 changes: 5 additions & 0 deletions src/Autocomplete/assets/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,17 @@ export default class extends Controller {
// the 'this.XXX' calls inside this method fail
load: function (query: string, callback: TomLoadCallback) {
const url = this.getUrl(query);
const dropdown = this.dropdown_content;
const scroll = dropdown ? dropdown.scrollTop : 0;
fetch(url)
.then((response) => response.json())
// important: next_url must be set before invoking callback()
.then((json) => {
this.setNextUrl(query, json.next_page);
callback(json.results.options || json.results, json.results.optgroups || []);
if (dropdown) {
dropdown.scrollTop = scroll;
}
})
.catch(() => callback([], []));
},
Expand Down
Loading