[Django] #30306: Textarea widget missing input_type

8 views
Skip to first unread message

Django

unread,
Apr 1, 2019, 5:53:08 PM4/1/19
to django-...@googlegroups.com
#30306: Textarea widget missing input_type
-----------------------------------------+------------------------
Reporter: minusf | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
(I tried to search for this both in here and the pull requests on github
but there is an eerie quiet about it.)

`Textarea` seems to be one of the few (if not the only) widget not
defining `input_type`.
I can't think of a good reason why it couldn't have one and some people
find out about this strange omission when they try to do something like:

{{{
for field in self.fields:
widget = self.fields[field].widget

if widget.input_type == "select":
...
elif widget.input_type == "checkbox":
...
}}}

but end up with:

{{{
...
AttributeError: 'Textarea' object has no attribute 'input_type'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30306>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 1, 2019, 10:20:16 PM4/1/19
to django-...@googlegroups.com
#30306: Textarea widget missing input_type
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Forms | Version: 2.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* type: Uncategorized => Cleanup/optimization
* resolution: => invalid


Comment:

What would a sensible value be? It doesn't seem applicable to me. The code
in question should use `if hasattr(widget, 'input_type')` as Django does.

--
Ticket URL: <https://code.djangoproject.com/ticket/30306#comment:1>

Django

unread,
Apr 2, 2019, 4:22:39 AM4/2/19
to django-...@googlegroups.com
#30306: Textarea widget missing input_type
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Forms | Version: 2.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by minusf):

Closed already? I think this is a fair bit of inconsistency and I would
welcome at least some discussion.

This is not just about not triggering an exception. This is about having
a useful way to identify widget types.
So textareas are the widgets that have no `input_type`? This makes
programmatic widget customisation painful.

As for the value, what's wrong with `'textarea'` ? Select has `select`,
checkbox has `checkbox`, etc. Even `hidden` has one.
Why should `textarea` be different?

{{{
class Input(Widget):
"""
Base class for all <input> widgets.
"""
input_type = None # Subclasses must define this.
<================= my emphasis
template_name = 'django/forms/widgets/input.html'

}}}

While this comment is in `Input` and not `Widget` (and `Textarea` inherits
from `Widget`) the intention and philosophy seems clear to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/30306#comment:2>

Django

unread,
Apr 2, 2019, 10:59:05 AM4/2/19
to django-...@googlegroups.com
#30306: Textarea widget missing input_type
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Forms | Version: 2.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

For `Input` subclasses, `input_type` corresponds to `<input type="...">`.
`ChoiceWidget` uses `input_type` for a different purpose.

--
Ticket URL: <https://code.djangoproject.com/ticket/30306#comment:3>

Django

unread,
Apr 2, 2019, 11:20:10 AM4/2/19
to django-...@googlegroups.com
#30306: Textarea widget missing input_type
-------------------------------------+-------------------------------------
Reporter: minusf | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Forms | Version: 2.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by minusf):

I understand that the "abstraction" is leaking. But `Select` and
`RadioSelect` both have `input_type`, even if for a "different purpose",
those can be used in the same way as `input_type` for "true" `Input`
widgets... It's not ideal, but it's already there and only `Textarea` is
left out in the cold. The other alternative could be to add `widget_type`
or such to every `Widget` subclass but at this point it would just
duplicate `input_type`.

--
Ticket URL: <https://code.djangoproject.com/ticket/30306#comment:4>

Reply all
Reply to author
Forward
0 new messages