mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 21:18:16 -06:00
Clear cached options when searching dynamic selects
This commit is contained in:
parent
1400065216
commit
35966cb988
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -2,6 +2,19 @@ import { getElements } from './util';
|
|||||||
import { TomOption } from 'tom-select/src/types';
|
import { TomOption } from 'tom-select/src/types';
|
||||||
import TomSelect from 'tom-select';
|
import TomSelect from 'tom-select';
|
||||||
|
|
||||||
|
|
||||||
|
class DynamicTomSelect extends TomSelect {
|
||||||
|
|
||||||
|
// Override load() to automatically clear any cached options. (Only options included
|
||||||
|
// in the API response should be present.)
|
||||||
|
load(value: string) {
|
||||||
|
this.clearOptions();
|
||||||
|
super.load(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize <select> elements with statically-defined options
|
||||||
function initStaticSelects(): void {
|
function initStaticSelects(): void {
|
||||||
|
|
||||||
for (const select of getElements<HTMLSelectElement>('select:not(.api-select):not(.color-select)')) {
|
for (const select of getElements<HTMLSelectElement>('select:not(.api-select):not(.color-select)')) {
|
||||||
@ -12,15 +25,16 @@ function initStaticSelects(): void {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize <select> elements which are populated via a REST API call
|
||||||
function initDynamicSelects(): void {
|
function initDynamicSelects(): void {
|
||||||
|
|
||||||
for (const select of getElements<HTMLSelectElement>('select.api-select')) {
|
for (const select of getElements<HTMLSelectElement>('select.api-select')) {
|
||||||
const api_url = select.getAttribute('data-url') as string;
|
const api_url = select.getAttribute('data-url') as string;
|
||||||
new TomSelect(select, {
|
new DynamicTomSelect(select, {
|
||||||
plugins: ['clear_button'],
|
plugins: ['clear_button'],
|
||||||
valueField: 'id',
|
valueField: 'id',
|
||||||
labelField: 'display',
|
labelField: 'display',
|
||||||
searchField: ['name'],
|
searchField: [],
|
||||||
copyClassesToDropdown: false,
|
copyClassesToDropdown: false,
|
||||||
dropdownParent: 'body',
|
dropdownParent: 'body',
|
||||||
controlInput: '<input>',
|
controlInput: '<input>',
|
||||||
@ -40,6 +54,7 @@ function initDynamicSelects(): void {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize color selection fields
|
||||||
function initColorSelects(): void {
|
function initColorSelects(): void {
|
||||||
|
|
||||||
for (const select of getElements<HTMLSelectElement>('select.color-select')) {
|
for (const select of getElements<HTMLSelectElement>('select.color-select')) {
|
||||||
|
Loading…
Reference in New Issue
Block a user