"Dan Jacob" <[EMAIL PROTECTED]> writes:
> 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.
Except for reusability... If the code is in the widget, you can use it in
several templates in several applications. I believe the point was making it
easy to implement a set of tools (widget = template + css + js + validators)
fast.
> 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")
I also think it is interesting to be able to override almost everything. :-)
> Alternatively use a dictionary:
>
> text = TextField("mytext", default="OK", attrs={'size':20})
> form = TableForm(attrs={'enctype':'multipart/form-data'})
Or both... But if it is to choose one, the dictionary looks better.
> 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"
+1 for that kind of change.
--
Jorge Godoy <[EMAIL PROTECTED]>