diff --git a/aleksis/core/forms.py b/aleksis/core/forms.py index 28b8b94562148dcf215e8129c995460c9a129dda..86dfed9dad0bf1d4a7c421527a7d63f67c4fe7af 100644 --- a/aleksis/core/forms.py +++ b/aleksis/core/forms.py @@ -5,7 +5,7 @@ from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ -from django_select2.forms import ModelSelect2MultipleWidget, Select2Widget +from django_select2.forms import ModelSelect2MultipleWidget, ModelSelect2Widget, Select2Widget from dynamic_preferences.forms import PreferenceForm from material import Fieldset, Layout, Row @@ -24,7 +24,7 @@ class PersonAccountForm(forms.ModelForm): class Meta: model = Person fields = ["last_name", "first_name", "user"] - widgets = {"user": Select2Widget} + widgets = {"user": Select2Widget(attrs={"class": "browser-default"})} new_user = forms.CharField(required=False) @@ -107,9 +107,19 @@ class EditPersonForm(ExtensibleForm): "primary_group", ] widgets = { - "user": Select2Widget, - "primary_group": Select2Widget, - "guardians": Select2Widget, + "user": Select2Widget(attrs={"class": "browser-default"}), + "primary_group": ModelSelect2Widget( + search_fields=["name__icontains", "short_name__icontains"], + attrs={"data-minimum-input-length": 0, "class": "browser-default"} + ), + "guardians": ModelSelect2Widget( + search_fields=[ + "first_name__icontains", + "last_name__icontains", + "short_name__icontains", + ], + attrs={"data-minimum-input-length": 0, "class": "browser-default"} + ), } new_user = forms.CharField( diff --git a/aleksis/core/templates/core/group/child_groups.html b/aleksis/core/templates/core/group/child_groups.html index bb5a429f6ec09effe094e14663f86187258919d3..589f8a6be18ac627c8e15d0ffc7924f86c557715 100644 --- a/aleksis/core/templates/core/group/child_groups.html +++ b/aleksis/core/templates/core/group/child_groups.html @@ -2,7 +2,14 @@ {% extends "core/base.html" %} -{% load i18n material_form %} +{% load i18n material_form any_js %} + + +{% block extra_head %} + {{ form.media.css }} + {% include_css "select2-materialize" %} +{% endblock %} + {% block browser_title %}{% blocktrans %}Assign child groups to groups{% endblocktrans %}{% endblock %} {% block page_title %} @@ -119,7 +126,7 @@ {% csrf_token %} - {% include "components/chips.html" with form_field=form.child_groups %} + {% form form=form %}{% endform %} <p class="left"> {% if page.has_previous %} @@ -151,4 +158,6 @@ </p> </form> {% endif %} + {% include_js "select2-materialize" %} + {{ form.media.js }} {% endblock %} diff --git a/aleksis/core/templates/core/person/accounts.html b/aleksis/core/templates/core/person/accounts.html index 672b089aaa949560e958d829597e1b7abd986265..03725518dfcbf8552a53199790daa44d541bac32 100644 --- a/aleksis/core/templates/core/person/accounts.html +++ b/aleksis/core/templates/core/person/accounts.html @@ -2,7 +2,12 @@ {% extends "core/base.html" %} -{% load i18n %} +{% load i18n any_js %} + +{% block extra_head %} + {{ persons_accounts_formset.media.css }} + {% include_css "select2-materialize" %} +{% endblock %} {% block browser_title %}{% blocktrans %}Link persons to accounts{% endblocktrans %}{% endblock %} {% block page_title %} @@ -55,4 +60,6 @@ {% blocktrans %}Update{% endblocktrans %} </button> </form> + {% include_js "select2-materialize" %} + {{ persons_accounts_formset.media.js }} {% endblock %} diff --git a/aleksis/core/templates/core/person/edit.html b/aleksis/core/templates/core/person/edit.html index 261249f6867a4370745f66d3bd0abc05891442cf..3bf16ca3521ea744acfe48c6829dfae21db06eb5 100644 --- a/aleksis/core/templates/core/person/edit.html +++ b/aleksis/core/templates/core/person/edit.html @@ -2,10 +2,11 @@ {% extends "core/base.html" %} -{% load material_form i18n %} +{% load material_form i18n any_js %} {% block extra_head %} {{ edit_person_form.media }} + {% include_css "select2-materialize" %} {% endblock %} {% block browser_title %}{% blocktrans %}Edit person{% endblocktrans %}{% endblock %} @@ -19,5 +20,7 @@ {% form form=edit_person_form %}{% endform %} {% include "core/partials/save_button.html" %} </form> + {% include_js "select2-materialize" %} + {{ edit_group_form.media.js }} {% endblock %} diff --git a/aleksis/core/templates/material/fields/django_select2_select2widget.html b/aleksis/core/templates/material/fields/django_select2_select2widget.html new file mode 100644 index 0000000000000000000000000000000000000000..1b19d8ec88bf72a694e32066c935327691c00738 --- /dev/null +++ b/aleksis/core/templates/material/fields/django_select2_select2widget.html @@ -0,0 +1,21 @@ +{% load l10n material_form material_form_internal %} +{% part bound_field.field %}<{{ field.widget.component|default:'dmc-select' }}> + <label>{{ bound_field.label }}</label> + <div class="row"> + <div{% attrs bound_field 'group' %} + id="id_{{ bound_field.html_name }}_container" + class="input-field col s12{% if field.required %} required{% endif %}{% if bound_field.errors %} has-error{% endif %}" + style="margin-top: 0" + {% endattrs %}> + {% part field prefix %}{% endpart %} + {% part field control %} + {{ bound_field }} + {% endpart %} + {% part field help_text %}{% if field.help_text %} + <div class="help-block">{{ bound_field.help_text|safe }}</div> + {% endif %}{% endpart %}{% part field errors %} + {% if bound_field.errors %} + {% include 'material/field_errors.html' %} + {% endif %}{% endpart %}{{ hidden_initial }} + </div> +</div></{{ field.widget.component|default:'dmc-select' }}>{% endpart %}