There is a ticket (106) related to this:
http://trac.turbogears.org/turbogears/ticket/106

(Please, don't pay attention to some of my crazy ideas.)

Anyway, I think that with compound widgets this becomes quite hard, a
solution is much needed to be sure that TG widgets really rock.

Ciao
Michele

Dan Jacob wrote:
> I've been trying to add new widgets to base.py and to my own test app,
> and I've found it's unnecessarily difficult to customize/extend
> existing widgets. For example:
>
> 1. I want to add a "size" attribute to a text field
> 2. I want the form to use enctype="multipart/form-data"
>
> In order to do these, I have to create a new template for that widget,
> which totally defeats the object of using widgets - it's a lot easier
> to just write the HTML in the template.
>
> Quixote seems to have a much more instinctive way of handling this :
> the attributes are passed in as keyword arguments. In TG it would work
> like this:
>
> text = TextField("mytext", default="OK", size=20)
> form = TableForm(enctype="multipart/form-data")
>
> Alternatively use a dictionary:
>
> text = TextField("mytext", default="OK", attrs={'size':20})
> form = TableForm(attrs={'enctype':'multipart/form-data'})
>
> Either would make it a lot easier to both write and extend widgets,
> instead of an inflexible template that has to be rewritten to do
> anything useful.  You could then create for example a basic InputField
> class like this:
>
> class InputField(Widget):
>     template = """<div xmlns:py="http://purl.org/kid/ns#";><input
> type="$widget.input_type" name="${widget.name}" value="${widget_value}"
> py:attrs="$widget.attrs"/>
> <span class="error"
> py:if="widget_error">${str(widget_error)}</span></div>
> """
> and then:
>
> class TextField(Widget):input_type="text"
> class PasswordField(Widget):input_type="password"
> class HiddenField(Widget):input_type="hidden"
> class FileField(Widget):input_type="file"

Reply via email to