On 11/05/2006, at 19:24, Dennis Muhlestein wrote:
> So extending your form a little....
>
> class MyFieldSet(FieldSet):
> fields=[
> TextField("foo", validator=Int(not_empty=True)),
> TextField("bar") ]
>
> class MySchema(Schema):
> chained_validators = [ validators.RequireIfMissing
> ( required='data2', missing='require2' ) ]
>
> class MyForm(Form):
> fields = [
> TextName("name"),
> MyFieldSet("data1"),
> CheckBox ( "require2" ),
> MyFieldSet("data2") ]
> validator = MySchema()
>
> The part I'm not too sure if it can be completed is how to not
> require any of the fields in data2 if the require2 field is not
> checked. Should the above example work? It isn't working for me
> but I'm not sure if it's something I've mistyped or done wrong, or
> if it just isn't possible with the framework.
Doh, didn't know about RequireIfMissing's existence and ended up
implementing something to do just that a long time ago... :(
I'ts basically a metaclass you can assign to any Validator class so
it will only 'kick-in' if some field in the form is checked. It uses
the 'state' argument to pass state along the schema so that field can
be at any level of nesting (IIRC).
If the example you're providing isn't working email me and I'll send
you what I've got. Sorry but cannot help on RequireIfMissing because,
as I've said, just know that it existed ;)
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
-~----------~----~----~----~------~----~------~--~---