mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-15 16:22:18 -06:00
cleanup
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,21 +75,17 @@ 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();
|
const currentValue = self.getValue();
|
||||||
|
|
||||||
// Clear cached options (only options from API response should be present)
|
|
||||||
self.clearOptions();
|
self.clearOptions();
|
||||||
|
|
||||||
// Clear user_options to prevent the pre-selected option from being treated specially
|
// Clear user_options to prevent the pre-selected option from being treated specially
|
||||||
(self as any).user_options = {};
|
(self as any).user_options = {};
|
||||||
|
|
||||||
// Populate the null option if not searching
|
|
||||||
if (self.nullOption && !value) {
|
if (self.nullOption && !value) {
|
||||||
self.addOption(self.nullOption);
|
self.addOption(self.nullOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the API request URL
|
|
||||||
const url = self.getRequestUrl(value);
|
const url = self.getRequestUrl(value);
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return;
|
return;
|
||||||
@@ -98,49 +94,31 @@ export class DynamicTomSelect extends TomSelect {
|
|||||||
addClasses(self.wrapper, self.settings.loadingClass);
|
addClasses(self.wrapper, self.settings.loadingClass);
|
||||||
self.loading++;
|
self.loading++;
|
||||||
|
|
||||||
// Make the API request
|
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(apiData => {
|
.then(apiData => {
|
||||||
const results: Dict[] = apiData.results;
|
const results: Dict[] = apiData.results;
|
||||||
|
|
||||||
// Add each option and then set $order to match API response order
|
// Add options and set $order to preserve API response order
|
||||||
results.forEach((result, index) => {
|
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 prevent it from being overwritten
|
|
||||||
const key = option[self.settings.valueField as string] as string;
|
const key = option[self.settings.valueField as string] as string;
|
||||||
if (self.options[key]) {
|
if (self.options[key]) {
|
||||||
(self.options[key] as any).$order = index;
|
(self.options[key] as any).$order = index;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Debug: log the $order values
|
|
||||||
console.log('Options after adding:');
|
|
||||||
for (const key in self.options) {
|
|
||||||
const opt = self.options[key] as any;
|
|
||||||
console.log(` ${opt.display} -> $order: ${opt.$order}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger loading complete
|
|
||||||
self.loading = Math.max(self.loading - 1, 0);
|
self.loading = Math.max(self.loading - 1, 0);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Before restore - currentValue:', currentValue, 'items:', self.items);
|
|
||||||
|
|
||||||
// Restore the selection
|
|
||||||
if (currentValue && !self.items.includes(currentValue as string)) {
|
if (currentValue && !self.items.includes(currentValue as string)) {
|
||||||
self.items.push(currentValue as string);
|
self.items.push(currentValue as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('After restore - items:', self.items);
|
|
||||||
|
|
||||||
// Refresh the dropdown display
|
|
||||||
self.refreshOptions(false);
|
self.refreshOptions(false);
|
||||||
|
|
||||||
console.log('After refreshOptions - items:', self.items);
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
self.loadCallback([], []);
|
self.loadCallback([], []);
|
||||||
|
|||||||
Reference in New Issue
Block a user