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