mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #7273: Disable automatic sorting of select options fetched via API
This commit is contained in:
@ -2202,9 +2202,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
api_url='/api/dcim/racks/{{rack}}/elevation/',
|
||||
attrs={
|
||||
'disabled-indicator': 'device',
|
||||
'data-query-param-face': "[\"$face\"]",
|
||||
# The UI will not sort this element's options.
|
||||
'pre-sorted': ''
|
||||
'data-query-param-face': "[\"$face\"]"
|
||||
}
|
||||
)
|
||||
)
|
||||
|
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
2
netbox/project-static/dist/netbox.js.map
vendored
2
netbox/project-static/dist/netbox.js.map
vendored
File diff suppressed because one or more lines are too long
@ -149,13 +149,6 @@ export class APISelect {
|
||||
*/
|
||||
private more: Nullable<string> = null;
|
||||
|
||||
/**
|
||||
* This element's options come from the server pre-sorted and should not be sorted client-side.
|
||||
* Determined by the existence of the `pre-sorted` attribute on the base `<select/>` element, or
|
||||
* by existence of specific fields such as `_depth`.
|
||||
*/
|
||||
private preSorted: boolean = false;
|
||||
|
||||
/**
|
||||
* Array of options values which should be considered disabled or static.
|
||||
*/
|
||||
@ -171,10 +164,6 @@ export class APISelect {
|
||||
this.base = base;
|
||||
this.name = base.name;
|
||||
|
||||
if (base.getAttribute('pre-sorted') !== null) {
|
||||
this.preSorted = true;
|
||||
}
|
||||
|
||||
if (hasUrl(base)) {
|
||||
const url = base.getAttribute('data-url') as string;
|
||||
this.url = url;
|
||||
@ -294,9 +283,7 @@ export class APISelect {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort incoming options by label and apply the new options to both the SlimSelect instance and
|
||||
* this manager's state. If the `preSorted` attribute exists on the base `<select/>` element,
|
||||
* the options will *not* be sorted.
|
||||
* Apply new options to both the SlimSelect instance and this manager's state.
|
||||
*/
|
||||
private set options(optionsIn: Option[]) {
|
||||
let newOptions = optionsIn;
|
||||
@ -304,12 +291,6 @@ export class APISelect {
|
||||
if (this.nullOption !== null) {
|
||||
newOptions = [this.nullOption, ...newOptions];
|
||||
}
|
||||
// Sort options unless this element is pre-sorted.
|
||||
if (!this.preSorted) {
|
||||
newOptions = newOptions.sort((a, b) =>
|
||||
a.text.toLowerCase() > b.text.toLowerCase() ? 1 : -1,
|
||||
);
|
||||
}
|
||||
// Deduplicate options each time they're set.
|
||||
const deduplicated = uniqueByProperty(newOptions, 'value');
|
||||
// Determine if the new options have a placeholder.
|
||||
@ -471,9 +452,6 @@ export class APISelect {
|
||||
|
||||
if (typeof result._depth === 'number' && result._depth > 0) {
|
||||
// If the object has a `_depth` property, indent its display text.
|
||||
if (!this.preSorted) {
|
||||
this.preSorted = true;
|
||||
}
|
||||
text = `<span class="depth">${'─'.repeat(result._depth)} </span>${text}`;
|
||||
}
|
||||
const data = {} as Record<string, string>;
|
||||
|
Reference in New Issue
Block a user