mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fix regression from ddff193
causing invalid selections
This commit is contained in:
14
netbox/project-static/dist/netbox.js
vendored
14
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
@ -22,6 +22,13 @@ import type { Stringifiable } from 'query-string';
|
|||||||
import type { Option } from 'slim-select/dist/data';
|
import type { Option } from 'slim-select/dist/data';
|
||||||
import type { Trigger, PathFilter, ApplyMethod, QueryFilter } from './types';
|
import type { Trigger, PathFilter, ApplyMethod, QueryFilter } from './types';
|
||||||
|
|
||||||
|
// Empty placeholder option.
|
||||||
|
const EMPTY_PLACEHOLDER = {
|
||||||
|
value: '',
|
||||||
|
text: '',
|
||||||
|
placeholder: true,
|
||||||
|
} as Option;
|
||||||
|
|
||||||
// Attributes which if truthy should render the option disabled.
|
// Attributes which if truthy should render the option disabled.
|
||||||
const DISABLED_ATTRIBUTES = ['occupied'] as string[];
|
const DISABLED_ATTRIBUTES = ['occupied'] as string[];
|
||||||
|
|
||||||
@ -45,7 +52,11 @@ export class APISelect {
|
|||||||
*/
|
*/
|
||||||
public readonly placeholder: string;
|
public readonly placeholder: string;
|
||||||
|
|
||||||
public readonly emptyOption: Nullable<Option> = null;
|
/**
|
||||||
|
* Empty/placeholder option. Display text is optionally overridden via the `data-empty-option`
|
||||||
|
* attribute.
|
||||||
|
*/
|
||||||
|
public readonly emptyOption: Option;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event that will initiate the API call to NetBox to load option data. By default, the trigger
|
* Event that will initiate the API call to NetBox to load option data. By default, the trigger
|
||||||
@ -142,7 +153,7 @@ export class APISelect {
|
|||||||
/**
|
/**
|
||||||
* This instance's available options.
|
* This instance's available options.
|
||||||
*/
|
*/
|
||||||
private _options: Option[] = [];
|
private _options: Option[] = [EMPTY_PLACEHOLDER];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of options values which should be considered disabled or static.
|
* Array of options values which should be considered disabled or static.
|
||||||
@ -169,6 +180,8 @@ export class APISelect {
|
|||||||
text: emptyOption,
|
text: emptyOption,
|
||||||
value: '',
|
value: '',
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
this.emptyOption = EMPTY_PLACEHOLDER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasUrl(base)) {
|
if (hasUrl(base)) {
|
||||||
@ -288,13 +301,13 @@ export class APISelect {
|
|||||||
// Get the placeholder index (note: if there is no placeholder, the index will be `-1`).
|
// Get the placeholder index (note: if there is no placeholder, the index will be `-1`).
|
||||||
const placeholderIdx = deduplicated.findIndex(o => o.value === '');
|
const placeholderIdx = deduplicated.findIndex(o => o.value === '');
|
||||||
|
|
||||||
if (hasPlaceholder && placeholderIdx < 0 && this.emptyOption !== null) {
|
if (hasPlaceholder && placeholderIdx < 0) {
|
||||||
// If there is a placeholder but it is not the first element (due to sorting or other merge
|
// If there is a placeholder but it is not the first element (due to sorting or other merge
|
||||||
// issues), remove it from the options array and place it in front.
|
// issues), remove it from the options array and place it in front.
|
||||||
deduplicated.splice(placeholderIdx);
|
deduplicated.splice(placeholderIdx);
|
||||||
deduplicated = [this.emptyOption, ...deduplicated];
|
deduplicated = [this.emptyOption, ...deduplicated];
|
||||||
}
|
}
|
||||||
if (!hasPlaceholder && this.emptyOption !== null) {
|
if (!hasPlaceholder) {
|
||||||
// If there is no placeholder, add one to the front of the array.
|
// If there is no placeholder, add one to the front of the array.
|
||||||
deduplicated = [this.emptyOption, ...deduplicated];
|
deduplicated = [this.emptyOption, ...deduplicated];
|
||||||
}
|
}
|
||||||
@ -306,11 +319,7 @@ export class APISelect {
|
|||||||
* Remove all options and reset back to the generic placeholder.
|
* Remove all options and reset back to the generic placeholder.
|
||||||
*/
|
*/
|
||||||
private resetOptions(): void {
|
private resetOptions(): void {
|
||||||
if (this.emptyOption !== null) {
|
this.options = [this.emptyOption];
|
||||||
this.options = [this.emptyOption];
|
|
||||||
} else {
|
|
||||||
this.options = [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user