1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

initial static select2 fields

This commit is contained in:
John Anderson
2019-01-03 23:02:05 -05:00
parent 5285b6926f
commit 81a0889568
4 changed files with 27 additions and 3 deletions

View File

@ -19,7 +19,7 @@ from utilities.forms import (
BulkEditNullBooleanSelect, ChainedFieldsMixin, ChainedModelChoiceField, ColorSelect, CommentField, ComponentForm, BulkEditNullBooleanSelect, ChainedFieldsMixin, ChainedModelChoiceField, ColorSelect, CommentField, ComponentForm,
ConfirmationForm, ContentTypeSelect, CSVChoiceField, ExpandableNameField, FilterChoiceField, ConfirmationForm, ContentTypeSelect, CSVChoiceField, ExpandableNameField, FilterChoiceField,
FilterTreeNodeMultipleChoiceField, FlexibleModelChoiceField, JSONField, Livesearch, SelectWithPK, SmallTextarea, 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 from virtualization.models import Cluster, ClusterGroup
@ -109,7 +109,10 @@ class RegionFilterForm(BootstrapMixin, forms.Form):
class SiteForm(BootstrapMixin, TenancyForm, CustomFieldForm): class SiteForm(BootstrapMixin, TenancyForm, CustomFieldForm):
region = TreeNodeChoiceField( region = TreeNodeChoiceField(
queryset=Region.objects.all(), queryset=Region.objects.all(),
required=False required=False,
widget=APISelect(
api_url="/api/dcim/regions/"
)
) )
slug = SlugField() slug = SlugField()
comments = CommentField() comments = CommentField()
@ -135,6 +138,8 @@ class SiteForm(BootstrapMixin, TenancyForm, CustomFieldForm):
'rows': 3, 'rows': 3,
} }
), ),
'status': StaticSelect2(),
'time_zone': StaticSelect2(),
} }
help_texts = { help_texts = {
'name': "Full name of the site", 'name': "Full name of the site",

View File

@ -81,9 +81,17 @@ $(document).ready(function() {
return rendered_url return rendered_url
} }
// Static choice selection
$('.netbox-select2-static').select2({
allowClear: true,
placeholder: "---------",
})
// API backed single selection // API backed single selection
// Includes live search and chained fields // Includes live search and chained fields
$('.netbox-select2-api').select2({ $('.netbox-select2-api').select2({
allowClear: true,
placeholder: "---------",
ajax: { ajax: {
delay: 500, delay: 500,
url: function(params) { url: function(params) {

View File

@ -1 +0,0 @@

View File

@ -336,6 +336,18 @@ class Livesearch(forms.TextInput):
self.attrs['data-label'] = obj_label 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 # Form fields
# #