diff --git a/opentech/apply/funds/forms.py b/opentech/apply/funds/forms.py index 51236a5927b8b6f79a8d58c6bb2509777890645a..8982f6afbb5f4abd553746ec03df1721573d9a9c 100644 --- a/opentech/apply/funds/forms.py +++ b/opentech/apply/funds/forms.py @@ -83,7 +83,8 @@ class UpdateReviewersForm(forms.ModelForm): self.fields[field_name] = forms.ModelChoiceField( queryset=staff_reviewers, widget=Select2IconWidget(attrs={ - 'data-placeholder': 'Select a reviewer', 'role': role}), + 'data-placeholder': 'Select a reviewer', 'icon': role.icon + }), required=False, label=f'{role.name} Reviewer', ) diff --git a/opentech/apply/funds/templates/funds/includes/delegated_form_base.html b/opentech/apply/funds/templates/funds/includes/delegated_form_base.html index a5e618774eae30212d3764c0f586e4f3a7f27db2..ec68b976b6dbc99ed62099e30b4f869f154ba5e6 100644 --- a/opentech/apply/funds/templates/funds/includes/delegated_form_base.html +++ b/opentech/apply/funds/templates/funds/includes/delegated_form_base.html @@ -2,23 +2,7 @@ <form class="form {{extra_classes}}" method="post" id="{{ form.name }}"> {% csrf_token %} <div class="form__item"> - {{ form.non_field_errors }} - - {% for field in form %} - {{ field.errors }} - - {# TODO: Add styles around icon later #} - {% if field.field.widget.attrs.role and field.field.widget.attrs.role.icon %} - {% image field.field.widget.attrs.role.icon max-20x20 %} - {% endif %} - - - {{ field.label_tag }} {{ field }} - - {% if field.help_text %} - {{ field.help_text|safe }} - {% endif %} - {% endfor %} + {{ form }} </div> <input class="button button--primary button--top-space" id="{{ form.name }}-submit" name="{{ form_prefix }}{{ form.name }}" type="submit" form="{{ form.name }}" value="{{ value }}"> diff --git a/opentech/apply/funds/templates/funds/widgets/icon_select2.html b/opentech/apply/funds/templates/funds/widgets/icon_select2.html new file mode 100644 index 0000000000000000000000000000000000000000..0449cc92a9ae92152ecc7b820adbc22209fffb9f --- /dev/null +++ b/opentech/apply/funds/templates/funds/widgets/icon_select2.html @@ -0,0 +1,3 @@ +{% load wagtailimages_tags %} +{% if widget.attrs.icon %}<div>{% image widget.attrs.icon max-20x20 %}</div>{% endif %} +{% include 'django/forms/widgets/select.html' %} diff --git a/opentech/apply/funds/widgets.py b/opentech/apply/funds/widgets.py index ecb2e9edeef1cfdfa644acd3cf78104c986f43f7..dbaf8ba228462006ed3bfa4080dfa8d9a69b03e9 100644 --- a/opentech/apply/funds/widgets.py +++ b/opentech/apply/funds/widgets.py @@ -23,8 +23,10 @@ class Select2MultiCheckboxesWidget(Select2MultipleWidget): class Select2IconWidget(Select2Widget): + template_name = 'funds/widgets/icon_select2.html' + def __init__(self, *args, **kwargs): attrs = kwargs.get('attrs', {}) - attrs.setdefault('role', '') + attrs.setdefault('icon', '') kwargs['attrs'] = attrs super().__init__(*args, **kwargs)