On 11/05/2006, at 18:02, mulicheng wrote:
>
> So after reading more documentation about both Widgets and the FE
> validators, from what I can see the benefits of the widgets package
> are:
>
> 1) You get a little bit cleaner error_handler decorator so you don't
> have to handle tg_errors yourself.
> 2) You get templates on the inputs to the form so that you don't have
> to write the std.xxx to check/set values in the form yourself.
>
> Did I miss any?
Yep,
1) they automatically include in the rendered page all needed
javascript and css resources needed to make them dance.
2) They are easy to pack in an egg (take a look at LightBox,
SelectShuttle, TinyMCE...) for reuse in other applications and
previewing in the Toolbox's widget browser.
> As a side note, you also get a few more validators in
> turbogears.validators that are not available in FE (or override FE
> validators that have bugs.) but I guess you could use those with
> the FE
> package without widgets.
Sure, no problem with that
> What I haven't found is how to make a widget form behave all the way
> like a Shema in FE. Specifically, I'm looking for the
> chained_validators functionality (so I can apply a few validators to
> the whole form). I see a Schema validator in the TG validators but
> haven't found an example or documentation on how to get this
> functionality.
You can attach a Schema validator to any CompoundInputWidget (a form,
for example) to validate it's child widgets.
class MySchema(Schema):
chained_validators = []
class MyForm(Form):
validator = MySchema()
There's a little bit of magic going behind scenes when you do this.
The form will build another schema, based on the schema to provide so
it includes all validators attached to child widgets, this way you
can do:
class MyFields(WidgetsList):
name = TextField(validator = String(not_empty=True))
class MyForm(Form):
validator = MySchema()
fields = MyFields()
The effective schema the form will use for validation will include
the String validator defined for the 'name' field.
HTH,
Alberto
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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
-~----------~----~----~----~------~----~------~--~---