2010/10/21 Daniel Garcia Moreno <[email protected]>:
> El mié, 20-10-2010 a las 13:46 -0700, Justin Davis escribió:
>> Ah, clarification, since you use "dir" you will get an alphabetical
>> list of the inputs. At least this is deterministic, though the order
>> is still not defined by the user.
>>
>> On Oct 20, 1:43 pm, Justin Davis <[email protected]> wrote:
>> > Correct me if I'm wrong, but I don't think this preserves the input
>> > order. getattr will just try to access the __dict__ of the object (and
>> > then the parent, etc), but it won't preserve order of the output. This
>> > means that calling render on that object will produce weird layouts.
>> >
>
> I fix that, now fields are ordered. I also make the sintax more clear,
> andrei commented that it would be much better if you didn't have to name
> your inputs twice, and I fixed it too. But for that I need to create
> other classes inside form because Input requires name param in __init__
> method.
>
> The new syntax is like that:
>
> from web import form
>
>
> class MyForm(form.Form):
>    name = form.TextboxField()
>    password = form.PasswordField()
>    password2 = form.PasswordField()
>
>    validator1 = form.Validator("Passwords didn't match.", lambda i:
> i.password == i.password2)
>
> And you can define validators as a list using __validators__ attr.
>
> As you can see, I don't use normal form.Input, I use inputname plus
> Field that is a class that inherit from the Input but has an __init__
> method that don't need name as first argument.

Looks good. Couple of comments:

* Can you try implementing this without using metaclass magic?

* I think it is better to specify validators using attribute
"validators" instead of adding each validator as an attribute or using
__validators__. Like this:

class MyForm(form.Form):
    name = form.TextboxField()
    password = form.PasswordField()
    password2 = form.PasswordField()

    validators = [
        form.Validator("Passwords didn't match.", lambda i: i.password
== i.password2)
    ]

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to