diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index dae5b5715..b6e1e4a77 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -19,7 +19,7 @@ from utilities.forms import ( BulkEditNullBooleanSelect, ChainedFieldsMixin, ChainedModelChoiceField, ColorSelect, CommentField, ComponentForm, ConfirmationForm, ContentTypeSelect, CSVChoiceField, ExpandableNameField, FilterChoiceField, FilterTreeNodeMultipleChoiceField, FlexibleModelChoiceField, JSONField, Livesearch, SelectWithPK, SmallTextarea, - SlugField, BOOLEAN_WITH_BLANK_CHOICES, COLOR_CHOICES, + SlugField, StaticSelect2, BOOLEAN_WITH_BLANK_CHOICES, COLOR_CHOICES, ) from virtualization.models import Cluster, ClusterGroup @@ -109,7 +109,10 @@ class RegionFilterForm(BootstrapMixin, forms.Form): class SiteForm(BootstrapMixin, TenancyForm, CustomFieldForm): region = TreeNodeChoiceField( queryset=Region.objects.all(), - required=False + required=False, + widget=APISelect( + api_url="/api/dcim/regions/" + ) ) slug = SlugField() comments = CommentField() @@ -135,6 +138,8 @@ class SiteForm(BootstrapMixin, TenancyForm, CustomFieldForm): 'rows': 3, } ), + 'status': StaticSelect2(), + 'time_zone': StaticSelect2(), } help_texts = { 'name': "Full name of the site", diff --git a/netbox/project-static/js/forms.js b/netbox/project-static/js/forms.js index b1c529dbb..6fbaaac66 100644 --- a/netbox/project-static/js/forms.js +++ b/netbox/project-static/js/forms.js @@ -81,9 +81,17 @@ $(document).ready(function() { return rendered_url } + // Static choice selection + $('.netbox-select2-static').select2({ + allowClear: true, + placeholder: "---------", + }) + // API backed single selection // Includes live search and chained fields $('.netbox-select2-api').select2({ + allowClear: true, + placeholder: "---------", ajax: { delay: 500, url: function(params) { diff --git a/netbox/project-static/js/netbox-select2.js b/netbox/project-static/js/netbox-select2.js deleted file mode 100644 index 8b1378917..000000000 --- a/netbox/project-static/js/netbox-select2.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/netbox/utilities/forms.py b/netbox/utilities/forms.py index 34d737317..618599cf0 100644 --- a/netbox/utilities/forms.py +++ b/netbox/utilities/forms.py @@ -336,6 +336,18 @@ class Livesearch(forms.TextInput): self.attrs['data-label'] = obj_label +class StaticSelect2(SelectWithDisabled): + """ + A static content using the Select2 widget + """ + + def __init__(self, *args, **kwargs): + + super().__init__(*args, **kwargs) + + self.attrs['class'] = 'netbox-select2-static' + + # # Form fields #