mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Feature 15832 - Multiselect has no "delete" option on the values (#15883)
* Added remove_button in config.ts * Fixed linter issues * Fixed linter issues * Fixed linter issues * Enable remove_button plugin only for multi-select fields * Enable remove_button plugin only for multi-select fields --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
6530051958
commit
4c93a2d084
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.
@ -1,9 +1,24 @@
|
|||||||
export const config = {
|
interface PluginConfig {
|
||||||
plugins: {
|
[plugin: string]: object;
|
||||||
// Provides the "clear" button on the widget
|
}
|
||||||
clear_button: {
|
|
||||||
html: (data: Dict) =>
|
export function getPlugins(element: HTMLSelectElement): object {
|
||||||
`<i class="mdi mdi-close-circle ${data.className}" title="${data.title}"></i>`,
|
const plugins: PluginConfig = {};
|
||||||
},
|
|
||||||
},
|
// Enable "clear all" button
|
||||||
};
|
plugins.clear_button = {
|
||||||
|
html: (data: Dict) =>
|
||||||
|
`<i class="mdi mdi-close-circle ${data.className}" title="${data.title}"></i>`,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Enable individual "remove" buttons for items on multi-select fields
|
||||||
|
if (element.hasAttribute('multiple')) {
|
||||||
|
plugins.remove_button = {
|
||||||
|
title: 'Remove',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
plugins: plugins,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { TomOption } from 'tom-select/src/types';
|
import { TomOption } from 'tom-select/src/types';
|
||||||
import { escape_html } from 'tom-select/src/utils';
|
import { escape_html } from 'tom-select/src/utils';
|
||||||
import { DynamicTomSelect } from './classes/dynamicTomSelect';
|
import { DynamicTomSelect } from './classes/dynamicTomSelect';
|
||||||
import { config } from './config';
|
import { getPlugins } from './config';
|
||||||
import { getElements } from '../util';
|
import { getElements } from '../util';
|
||||||
|
|
||||||
const VALUE_FIELD = 'id';
|
const VALUE_FIELD = 'id';
|
||||||
@ -44,7 +44,7 @@ function renderItem(data: TomOption, escape: typeof escape_html) {
|
|||||||
export function initDynamicSelects(): void {
|
export function initDynamicSelects(): void {
|
||||||
for (const select of getElements<HTMLSelectElement>('select.api-select:not(.tomselected)')) {
|
for (const select of getElements<HTMLSelectElement>('select.api-select:not(.tomselected)')) {
|
||||||
new DynamicTomSelect(select, {
|
new DynamicTomSelect(select, {
|
||||||
...config,
|
...getPlugins(select),
|
||||||
valueField: VALUE_FIELD,
|
valueField: VALUE_FIELD,
|
||||||
labelField: LABEL_FIELD,
|
labelField: LABEL_FIELD,
|
||||||
maxOptions: MAX_OPTIONS,
|
maxOptions: MAX_OPTIONS,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { TomOption } from 'tom-select/src/types';
|
import { TomOption } from 'tom-select/src/types';
|
||||||
import TomSelect from 'tom-select';
|
import TomSelect from 'tom-select';
|
||||||
import { escape_html } from 'tom-select/src/utils';
|
import { escape_html } from 'tom-select/src/utils';
|
||||||
import { config } from './config';
|
import { getPlugins } from './config';
|
||||||
import { getElements } from '../util';
|
import { getElements } from '../util';
|
||||||
|
|
||||||
// Initialize <select> elements with statically-defined options
|
// Initialize <select> elements with statically-defined options
|
||||||
@ -10,7 +10,7 @@ export function initStaticSelects(): void {
|
|||||||
'select:not(.tomselected):not(.no-ts):not([size]):not(.api-select):not(.color-select)',
|
'select:not(.tomselected):not(.no-ts):not([size]):not(.api-select):not(.color-select)',
|
||||||
)) {
|
)) {
|
||||||
new TomSelect(select, {
|
new TomSelect(select, {
|
||||||
...config,
|
...getPlugins(select),
|
||||||
maxOptions: undefined,
|
maxOptions: undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ export function initColorSelects(): void {
|
|||||||
|
|
||||||
for (const select of getElements<HTMLSelectElement>('select.color-select:not(.tomselected)')) {
|
for (const select of getElements<HTMLSelectElement>('select.color-select:not(.tomselected)')) {
|
||||||
new TomSelect(select, {
|
new TomSelect(select, {
|
||||||
...config,
|
...getPlugins(select),
|
||||||
maxOptions: undefined,
|
maxOptions: undefined,
|
||||||
render: {
|
render: {
|
||||||
option: renderColor,
|
option: renderColor,
|
||||||
|
Loading…
Reference in New Issue
Block a user