Opened 10 years ago

Last modified 2 years ago

#13009 assigned New feature

provide django.forms field type info for use in templates

Reported by: Tom von Schwerdtner Owned by: rameshugar
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


My use case is that it would be useful to have access to this info from templates when generating forms, eg:

{% for field in form.fields %}
    {% if field.type == 'checkbox' %}
      {# render one way... #}
    {% else %}
      {# render another way #}
    {% endif %}
{% endfor %}

FWIW, django.contrib.admin seems to get around this problem in AdminField by adding an is_checkbox attribute, but it seems to me that the type of field being rendered should be easily available in the template, in other words, IMHO this makes sense as a core feature of django.forms.

Change History (6)

comment:1 Changed 10 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

Broadly the idea has merit, but it needs a bit of finesse - specifically, what determines the "type" of the field? Do we just use the type of the input element on the widget? What do we do in the case of multi-widgets?

Unfortunately, the solution used in admin isn't a great reference point. Admin has control of all it's widgets, and the way in which they are used. This isn't true of the broader widget framework, which must integrate with arbitrary external widgets, used in unknown ways.

comment:2 Changed 9 years ago by Luke Plant

Type: New feature

comment:3 Changed 9 years ago by Luke Plant

Severity: Normal

comment:4 Changed 8 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 Changed 8 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 Changed 2 years ago by rameshugar

Owner: changed from nobody to rameshugar
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top