#18242: Making widget type accessible in template
-----------------------------+--------------------
Reporter: selwin | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 1.3
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
Hi there,
Is there a possibility to add a `type` attribute to form widgets? The goal
is to make it easy for designers to apply different styles to each widget
type while keeping the template code DRY.
Django's current source code already does something similar for "<input>"
based widgets such as `TextInput` and `DateInput` (though for a different
purpose). These widgets have `input_type` attribute attached to them so we
can already do:
{{{
<ul>
{% for field in form %}
<li class = '{{ field.field.widget.input_type }}'>
{{ field }}
</li>
{% endfor %}
</ul>
}}}
But the above means we can only target `input` based widgets and not
`select`, `textarea` etc. If we add a more generic `type` (e.g "select",
"checkbox", "textarea") attribute to widgets, we'll be able to do:
{{{
<ul>
{% for field in form %}
<li class = '{{ field.field.widget.type }}'>
{{ field }}
</li>
{% endfor %}
</ul>
}}}
Or even better (if we attach widgets to `BoundField`):
{{{
<ul>
{% for field in form %}
<li class = '{{ field.widget.type }}'>
{{ field }}
</li>
{% endfor %}
</ul>
}}}
If it sounds like a good idea, I'd be more than willing to try writing a
patch for this.
--
Ticket URL: <https://code.djangoproject.com/ticket/18242>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.