diff --git a/opentech/apply/funds/templates/funds/widgets/nested_with_label.html b/opentech/apply/funds/templates/funds/widgets/nested_with_label.html new file mode 100644 index 0000000000000000000000000000000000000000..c1c7d0d48c7fe57cc9bcc60dc907cb1e1d09154f --- /dev/null +++ b/opentech/apply/funds/templates/funds/widgets/nested_with_label.html @@ -0,0 +1,14 @@ +<div {% include "django/forms/widgets/attrs.html" %}>{% spaceless %} + {% for widget in widget.subwidgets %} + {% if not widget.subwidgets %} + <div class="form__item"> + <label for="{{ widget.attrs.id }}">{{ widget.attrs.name.title }}</label> + {% endif %} + + {% include widget.template_name %} + + {% if not widget.subwidgets %} + </div> + {% endif %} + {% endfor %} +{% endspaceless %}</div> diff --git a/opentech/apply/funds/widgets.py b/opentech/apply/funds/widgets.py index 1537260806748030504ca21306c48a008dde8f89..78b3ec452b75e4ec17a6c42d9289afdc01cf9e68 100644 --- a/opentech/apply/funds/widgets.py +++ b/opentech/apply/funds/widgets.py @@ -6,7 +6,7 @@ from django_countries import countries class KeepOwnAttrsWidget(forms.Widget): def get_context(self, name, value, attrs): - name = self.attrs.pop('name') or name + name = self.attrs.get('name') or name attrs.update(self.attrs) return super().get_context(name, value, attrs) @@ -22,6 +22,8 @@ class KeepAttrsTextInput(KeepOwnAttrsWidget, forms.TextInput): class NestedMultiWidget(forms.MultiWidget): + template_name = 'funds/widgets/nested_with_label.html' + def __init__(self, *args, **kwargs): widgets = [ widget(attrs={'name': field}) for field, widget in self.components.items() diff --git a/opentech/templates/django/forms/widgets/multiwidget.html b/opentech/templates/django/forms/widgets/multiwidget.html deleted file mode 100644 index cf6424162baa883b2bdded09f337a225ca18f49a..0000000000000000000000000000000000000000 --- a/opentech/templates/django/forms/widgets/multiwidget.html +++ /dev/null @@ -1 +0,0 @@ -<div {% include "django/forms/widgets/attrs.html" %}>{% spaceless %}{% for widget in widget.subwidgets %}{% include widget.template_name %}{% endfor %}{% endspaceless %}</div>