mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
initial static select2 fields
This commit is contained in:
parent
5285b6926f
commit
81a0889568
@ -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",
|
||||
|
@ -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) {
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -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
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user