Skip to content
Snippets Groups Projects
Commit df4d3c0e authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Update the template to output tidier html

parent f63c8b18
No related branches found
No related tags found
No related merge requests found
<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>
...@@ -6,7 +6,7 @@ from django_countries import countries ...@@ -6,7 +6,7 @@ from django_countries import countries
class KeepOwnAttrsWidget(forms.Widget): class KeepOwnAttrsWidget(forms.Widget):
def get_context(self, name, value, attrs): 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) attrs.update(self.attrs)
return super().get_context(name, value, attrs) return super().get_context(name, value, attrs)
...@@ -22,6 +22,8 @@ class KeepAttrsTextInput(KeepOwnAttrsWidget, forms.TextInput): ...@@ -22,6 +22,8 @@ class KeepAttrsTextInput(KeepOwnAttrsWidget, forms.TextInput):
class NestedMultiWidget(forms.MultiWidget): class NestedMultiWidget(forms.MultiWidget):
template_name = 'funds/widgets/nested_with_label.html'
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
widgets = [ widgets = [
widget(attrs={'name': field}) for field, widget in self.components.items() widget(attrs={'name': field}) for field, widget in self.components.items()
......
<div {% include "django/forms/widgets/attrs.html" %}>{% spaceless %}{% for widget in widget.subwidgets %}{% include widget.template_name %}{% endfor %}{% endspaceless %}</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment