Kevin Dangoor wrote:
>
> Using Widgets
> -------------
>
> Here's an example from the "first look":
> widgets.TextField("age", default=0, validator=validators.Int())
This might seem strange, but first thing that jumps out about this
example is the "style" doesn't feel right. Or at least it doesn't feel
consistent with sqlobject. Maybe something more like this:
class MyForm (widgets.Form):
age = widgets.TextField(
default=0,
validators=(
validators.Int(min=4, max=12),
validators.Required())
I still need to read about formencode, so I'm not sure if my list of
validators even makes sense. Now that I think of it, composition (ala
composite pattern) would probably beat lists for testability anyway.
> Widgets have two similar methods for using them: insert and render. In
> practice, insert is the one that is used most often. The difference
> between them is that render returns HTML (or whatever text form you're
> expecting) and insert returns a Element generator, which is convenient
> for inclusion in a surrounding Kid template.
Smart! I like it.
> The validator is important because you can have something like a
> select widget that needs to translate between IDs and names. Or, you
> could have a repeating form element widget that takes in a collection
> of data as its value.
Hmm. I really need to go read about formencode.... (going now :)