Skip to content

Commit f164cb5

Browse files
committed
add adminlte/widgets/select.html && auto active select2 by select id
1 parent b92ebc1 commit f164cb5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<select name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>{% for group_name, group_choices, group_index in widget.optgroups %}{% if group_name %}
2+
<optgroup label="{{ group_name }}">{% endif %}{% for option in group_choices %}
3+
{% include option.template_name with widget=option %}{% endfor %}{% if group_name %}
4+
</optgroup>{% endif %}{% endfor %}
5+
</select>
6+
<script>django.jQuery('#id_{{widget.name}}').select2()</script>

adminlteui/widgets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
class AdminlteSelect(Select):
6+
template_name = "adminlte/widgets/select.html"
67

78
def _get_media(self):
89
return forms.Media(
@@ -17,6 +18,8 @@ def _get_media(self):
1718

1819

1920
class AdminlteSelectMultiple(SelectMultiple):
21+
template_name = "adminlte/widgets/select.html"
22+
2023
def build_attrs(self, base_attrs, extra_attrs=None):
2124
extra_attrs['multiple'] = 'multiple'
2225
return {**base_attrs, **(extra_attrs or {})}

0 commit comments

Comments
 (0)