Alberto Valverde wrote:
>
> > I think this should work, should we wrap the validator with Any and
> > All
> > in the final schema or do it inside every form field (decorating the
> > init method) and then use that in the Schema?
>
> I guess it's best to keep all this magic inside meta, so I'd say do
> it in the generate_schema phase. That way there's no need to decorate
> __init__ any further (remember that generate_schema runs in an
> __init__ decorator already)
>

OK, I've uploaded a patch in the trac:

http://trac.turbogears.org/turbogears/attachment/ticket/696/easy_is_required_for_fields.patch

Please take a look and comment. :-)

The way it works is this, any field by default is not required
(is_required=False) and hence even a validator like Int() will give you
a not required field (while ATM FE claims not_empty=False, Int() in
reality not_empty=False and this is long standing issue IMHO that we
finally fix in this way), for fields that provide a default validator
you just need to use is_required=True, if you're providing a validator
you can use or not_empty or is_required (it this version of the patch I
forgot to give them the same value if they are different).

example:

TextField(validator=Int()) -> field not required
TextField(validator=Int(), is_required=True) -> field required
TextField(validator=Int(not_empty=True)) -> field_required
TextField(validator=Int(not_empty=True), is_required=False) ->
field_required

Opinions on this? I don't like the last one but I can't see anything
better as a solution.

One thing that I would really like to do is to move this thing and the
generate_schema thing to a MetaInputWidget metaclass since we only need
these things for InputWidget(s) and not for the plain Widget and
CompoundWidget class, this will let us (at some point) give a shot at
making self.validator a property that uses the schema validator from
the path if present. ;-)

Ciao
Michele


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" 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/turbogears-trunk
-~----------~----~----~----~------~----~------~--~---

Reply via email to