fix selected item sorting

This commit is contained in:
Arthur
2026-01-14 14:35:45 -08:00
parent 6317bcc657
commit 05619a9745
3 changed files with 17 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -79,6 +79,9 @@ export class DynamicTomSelect extends TomSelect {
// in the API response should be present.)
self.clearOptions();
// Clear user_options to prevent the pre-selected option from being treated specially
(self as any).user_options = {};
// Populate the null option (if any) if not searching
if (self.nullOption && !value) {
self.addOption(self.nullOption);
@@ -98,16 +101,19 @@ export class DynamicTomSelect extends TomSelect {
.then(response => response.json())
.then(apiData => {
const results: Dict[] = apiData.results;
const options: Dict[] = [];
// Add options directly (TomSelect automatically sets $order based on insertion order)
for (const result of results) {
const option = self.getOptionFromData(result);
options.push(option);
self.addOption(option);
}
return options;
})
// Pass the options to the callback function
.then(options => {
self.loadCallback(options, []);
self.loading--;
if (self.loading === 0) {
self.wrapper.classList.remove(self.settings.loadingClass as string);
}
self.refreshOptions(false);
})
.catch(() => {
self.loadCallback([], []);