`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.
* 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>
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>
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>
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>