mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Enable widget usage (APISelect, APIMultipleSelect, StaticSelect2, etc) in scripts
This commit is contained in:
parent
a54fcda781
commit
3c3cca8ec1
@ -48,7 +48,7 @@ class ScriptVariable:
|
|||||||
"""
|
"""
|
||||||
form_field = forms.CharField
|
form_field = forms.CharField
|
||||||
|
|
||||||
def __init__(self, label='', description='', default=None, required=True):
|
def __init__(self, label='', description='', default=None, required=True, widget=None):
|
||||||
|
|
||||||
# Initialize field attributes
|
# Initialize field attributes
|
||||||
if not hasattr(self, 'field_attrs'):
|
if not hasattr(self, 'field_attrs'):
|
||||||
@ -59,6 +59,8 @@ class ScriptVariable:
|
|||||||
self.field_attrs['help_text'] = description
|
self.field_attrs['help_text'] = description
|
||||||
if default:
|
if default:
|
||||||
self.field_attrs['initial'] = default
|
self.field_attrs['initial'] = default
|
||||||
|
if widget:
|
||||||
|
self.field_attrs['widget'] = widget
|
||||||
self.field_attrs['required'] = required
|
self.field_attrs['required'] = required
|
||||||
|
|
||||||
# Initialize the list of optional validators if none have already been defined
|
# Initialize the list of optional validators if none have already been defined
|
||||||
@ -71,7 +73,10 @@ class ScriptVariable:
|
|||||||
"""
|
"""
|
||||||
form_field = self.form_field(**self.field_attrs)
|
form_field = self.form_field(**self.field_attrs)
|
||||||
if not isinstance(form_field.widget, forms.CheckboxInput):
|
if not isinstance(form_field.widget, forms.CheckboxInput):
|
||||||
form_field.widget.attrs['class'] = 'form-control'
|
if form_field.widget.attrs and form_field.widget.attrs['class']:
|
||||||
|
form_field.widget.attrs['class'] += ' form-control'
|
||||||
|
else:
|
||||||
|
form_field.widget.attrs['class'] = 'form-control'
|
||||||
|
|
||||||
return form_field
|
return form_field
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user