Răsfoiți Sursa

initial static select2 fields

John Anderson 7 ani în urmă
părinte
comite
81a0889568

+ 7 - 2
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",

+ 8 - 0
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) {

+ 0 - 1
netbox/project-static/js/netbox-select2.js

@@ -1 +0,0 @@
-

+ 12 - 0
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
 #