Provide forms field/widget type information for use in templates

51 views
Skip to first unread message

Paweł Adamczak

unread,
Mar 20, 2017, 12:19:57 PM3/20/17
to Django developers (Contributions to Django itself)
Hiya,

I would like to 'resurrect' ticket #13009, or at least discuss it.

I think that the suggested feature would be beneficial, as it comes up every time I'm implementing HTML flats different types of fields require different rendering (the most common example being checkboxes, where the input field is before the label). Adding an easy, builtin method of checking the field type/widget would be much nicer in my opinion then using then using  - just for example - this approach.


From the ticket:
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?
 
As far as I understand Django tries to structure its widget structure based on the HTML spec, and I would follow that convention as close as possible, with widget 'types' (the nomenclature would probably need to be different) like 'input_text', 'input_email', ..., 'input_radio', 'input_checkbox', and 'select'. In other cases we would just mimic the widget name ('multi_widget'). 

What do you think?
I would be happy to contribute to Django and implement the above in a feature pull request.

Collin Anderson

unread,
Mar 20, 2017, 12:36:17 PM3/20/17
to django-d...@googlegroups.com
Hi,

If it helps It looks like there's a widget.input_type attribute, so you can at least do {% if theform.thefield.field.widget.input_type == "checkbox" %} etc. 

Collin


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/02725db5-3873-4651-9f2e-01c7b2af9f85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paweł Adamczak

unread,
Mar 20, 2017, 3:30:40 PM3/20/17
to Django developers (Contributions to Django itself)
Huh, don't know how I missed that. Thanks!

In that case, I would add the information to the docs, to the ticket, and close it : -)


On Monday, March 20, 2017 at 4:36:17 PM UTC, Collin Anderson wrote:
Hi,

If it helps It looks like there's a widget.input_type attribute, so you can at least do {% if theform.thefield.field.widget.input_type == "checkbox" %} etc. 

Collin

On Mon, Mar 20, 2017 at 9:46 AM, Paweł Adamczak <pawe...@gmail.com> wrote:
Hiya,

I would like to 'resurrect' ticket #13009, or at least discuss it.

I think that the suggested feature would be beneficial, as it comes up every time I'm implementing HTML flats different types of fields require different rendering (the most common example being checkboxes, where the input field is before the label). Adding an easy, builtin method of checking the field type/widget would be much nicer in my opinion then using then using  - just for example - this approach.


From the ticket:
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?
 
As far as I understand Django tries to structure its widget structure based on the HTML spec, and I would follow that convention as close as possible, with widget 'types' (the nomenclature would probably need to be different) like 'input_text', 'input_email', ..., 'input_radio', 'input_checkbox', and 'select'. In other cases we would just mimic the widget name ('multi_widget'). 

What do you think?
I would be happy to contribute to Django and implement the above in a feature pull request.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages