diff --git a/netbox/project-static/dist/netbox.js b/netbox/project-static/dist/netbox.js index 6ca2fc7a2..7033c4b25 100644 Binary files a/netbox/project-static/dist/netbox.js and b/netbox/project-static/dist/netbox.js differ diff --git a/netbox/project-static/dist/netbox.js.map b/netbox/project-static/dist/netbox.js.map index 48669be3f..63faabef2 100644 Binary files a/netbox/project-static/dist/netbox.js.map and b/netbox/project-static/dist/netbox.js.map differ diff --git a/netbox/project-static/src/select/api.ts b/netbox/project-static/src/select/api.ts index abdacc3ce..b6ef0ea0d 100644 --- a/netbox/project-static/src/select/api.ts +++ b/netbox/project-static/src/select/api.ts @@ -123,6 +123,11 @@ class APISelect { */ private disabledOptions: Array = []; + /** + * Array of properties which if truthy on an API object should be considered disabled. + */ + private disabledAttributes: Array = DISABLED_ATTRIBUTES; + constructor(base: HTMLSelectElement) { // Initialize readonly properties. this.base = base; @@ -141,6 +146,7 @@ class APISelect { this.loadEvent = new Event(`netbox.select.onload.${base.name}`); this.placeholder = this.getPlaceholder(); this.disabledOptions = this.getDisabledOptions(); + this.disabledAttributes = this.getDisabledAttributes(); this.slim = new SlimSelect({ select: this.base, @@ -335,7 +341,7 @@ class APISelect { data[key] = String(v); } // Set option to disabled if the result contains a matching key and is truthy. - if (DISABLED_ATTRIBUTES.some(key => key.toLowerCase() === k.toLowerCase())) { + if (this.disabledAttributes.some(key => key.toLowerCase() === k.toLowerCase())) { if (typeof v === 'string' && v.toLowerCase() !== 'false') { disabled = true; } else if (typeof v === 'boolean' && v === true) { @@ -546,6 +552,19 @@ class APISelect { return disabledOptions; } + /** + * Get this element's disabled attribute keys. For example, if `disabled-indicator` is set to + * `'_occupied'` and an API object contains `{ _occupied: true }`, the option will be disabled. + */ + private getDisabledAttributes(): string[] { + let disabled = [...DISABLED_ATTRIBUTES] as string[]; + const attr = this.base.getAttribute('disabled-indicator'); + if (isTruthy(attr)) { + disabled = [...disabled, attr]; + } + return disabled; + } + /** * Parse the `data-url` attribute to add any Django template variables to `pathValues` as keys * with empty values. As those keys' corresponding form fields' values change, `pathValues` will