mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 21:18:16 -06:00
Introduce custom form widget templates to apply CSS classes
This commit is contained in:
parent
073c2dc8ca
commit
c2b0ac3d02
@ -4,4 +4,4 @@
|
||||
_selected_action to avoid breaking the admin UI.
|
||||
{% endcomment %}
|
||||
{% if widget.name != '_selected_action' %}<input type="hidden" name="{{ widget.name }}" value="">{% endif %}
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
<input type="checkbox" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %} {% include "django/forms/widgets/attrs.html" %} class="{{ widget.attrs.class }} form-check-input">
|
||||
|
1
netbox/templates/django/forms/widgets/input.html
Normal file
1
netbox/templates/django/forms/widgets/input.html
Normal file
@ -0,0 +1 @@
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} class="{{ widget.attrs.class }} form-control">
|
5
netbox/templates/django/forms/widgets/select.html
Normal file
5
netbox/templates/django/forms/widgets/select.html
Normal file
@ -0,0 +1,5 @@
|
||||
<select name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} class="{{ widget.attrs.class }} {% if 'size' in widget.attrs %}form-select form-select-sm{% else %}netbox-static-select{% endif %}">{% for group_name, group_choices, group_index in widget.optgroups %}{% if group_name %}
|
||||
<optgroup label="{{ group_name }}">{% endif %}{% for option in group_choices %}
|
||||
{% include option.template_name with widget=option %}{% endfor %}{% if group_name %}
|
||||
</optgroup>{% endif %}{% endfor %}
|
||||
</select>
|
2
netbox/templates/django/forms/widgets/textarea.html
Normal file
2
netbox/templates/django/forms/widgets/textarea.html
Normal file
@ -0,0 +1,2 @@
|
||||
<textarea name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} class="{{ widget.attrs.class }} form-control">
|
||||
{% if widget.value %}{{ widget.value }}{% endif %}</textarea>
|
@ -32,18 +32,18 @@ class BootstrapMixin:
|
||||
if field.widget.__class__ in exempt_widgets:
|
||||
continue
|
||||
|
||||
elif isinstance(field.widget, forms.CheckboxInput):
|
||||
field.widget.attrs['class'] = f'{css} form-check-input'
|
||||
|
||||
elif isinstance(field.widget, forms.SelectMultiple) and 'size' in field.widget.attrs:
|
||||
# Use native Bootstrap class for multi-line <select> widgets
|
||||
field.widget.attrs['class'] = f'{css} form-select form-select-sm'
|
||||
|
||||
elif isinstance(field.widget, (forms.Select, forms.SelectMultiple)):
|
||||
field.widget.attrs['class'] = f'{css} netbox-static-select'
|
||||
|
||||
else:
|
||||
field.widget.attrs['class'] = f'{css} form-control'
|
||||
# elif isinstance(field.widget, forms.CheckboxInput):
|
||||
# field.widget.attrs['class'] = f'{css} form-check-input'
|
||||
#
|
||||
# elif isinstance(field.widget, forms.SelectMultiple) and 'size' in field.widget.attrs:
|
||||
# # Use native Bootstrap class for multi-line <select> widgets
|
||||
# field.widget.attrs['class'] = f'{css} form-select form-select-sm'
|
||||
#
|
||||
# elif isinstance(field.widget, (forms.Select, forms.SelectMultiple)):
|
||||
# field.widget.attrs['class'] = f'{css} netbox-static-select'
|
||||
#
|
||||
# else:
|
||||
# field.widget.attrs['class'] = f'{css} form-control'
|
||||
|
||||
if field.required and not isinstance(field.widget, forms.FileInput):
|
||||
field.widget.attrs['required'] = 'required'
|
||||
|
Loading…
Reference in New Issue
Block a user