mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-17 01:02:18 -06:00
fix selected item sorting
This commit is contained in:
2
netbox/project-static/dist/netbox.js
vendored
2
netbox/project-static/dist/netbox.js
vendored
File diff suppressed because one or more lines are too long
6
netbox/project-static/dist/netbox.js.map
vendored
6
netbox/project-static/dist/netbox.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -75,6 +75,9 @@ export class DynamicTomSelect extends TomSelect {
|
|||||||
load(value: string) {
|
load(value: string) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
|
// Save current selection before clearing
|
||||||
|
const currentValue = self.getValue();
|
||||||
|
|
||||||
// Automatically clear any cached options. (Only options included
|
// Automatically clear any cached options. (Only options included
|
||||||
// in the API response should be present.)
|
// in the API response should be present.)
|
||||||
self.clearOptions();
|
self.clearOptions();
|
||||||
@@ -102,17 +105,27 @@ export class DynamicTomSelect extends TomSelect {
|
|||||||
.then(apiData => {
|
.then(apiData => {
|
||||||
const results: Dict[] = apiData.results;
|
const results: Dict[] = apiData.results;
|
||||||
|
|
||||||
// Add options directly (TomSelect automatically sets $order based on insertion order)
|
// Add options and manually set $order to ensure correct sorting
|
||||||
for (const result of results) {
|
results.forEach((result, index) => {
|
||||||
const option = self.getOptionFromData(result);
|
const option = self.getOptionFromData(result);
|
||||||
self.addOption(option);
|
self.addOption(option);
|
||||||
}
|
// Set $order after addOption() to override any special handling of pre-selected items
|
||||||
|
const key = option[self.settings.valueField as string] as string;
|
||||||
|
if (self.options[key]) {
|
||||||
|
(self.options[key] as any).$order = index;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
self.loading--;
|
self.loading--;
|
||||||
if (self.loading === 0) {
|
if (self.loading === 0) {
|
||||||
self.wrapper.classList.remove(self.settings.loadingClass as string);
|
self.wrapper.classList.remove(self.settings.loadingClass as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore the current selection
|
||||||
|
if (currentValue && !self.items.includes(currentValue as string)) {
|
||||||
|
self.items.push(currentValue as string);
|
||||||
|
}
|
||||||
|
|
||||||
self.refreshOptions(false);
|
self.refreshOptions(false);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user