iain duncan schrieb:
> On Thu, 2007-21-06 at 08:50 +0200, Diez B. Roggisch wrote:
>> iain duncan schrieb:
>>> Wondering if there is a smart way to add fields to a form widget based
>>> on runtime factors ( ie a db hit ) or whether this is just asking for
>>> trouble with form encode. Anyone do this? And if so, how do you handle
>>> validation?
>> Depending on your situation, you can do this:
>>
>> class FeatureSchema(validators.Schema):
>>      selected_quantity = validators.Int(not_empty=True)
>>      chosen = validators.Int(not_emtpy=True)
>>      comment = validators.FancyValidator()
>>
>> class OccupancySchema(validators.Schema):
>>      start_time = varms_validators.Duration(not_empty=True)
>>      end_time = varms_validators.Duration(not_empty=True)
>>      features = formencode.ForEach(FeatureSchema())
>>
>> That will make features an arbitrary number of FeatureSchema-values.
> 
> Thanks Diez ( again! ). What I would really like to do is make the
> number of some certain fields vary with a dynamic value from the db. I'm
> not clear from the above whether that is possible. Does the example
> above mean that the number of feature schema validated is just
> determined by the number of incoming variables to formencode? 

It is dependend from the numbers of incoming variables, as they have to 
be named in the proper way.

For the case at hand that means that features are given like this

features-1.selected_quantity
features-2.selected_quantity

Obviously you have to render the form fields accordingly. Unfortunately 
I'm not sure right now how that happens exactly, because the code above 
is validating some JS-generated forms. But AFAIK using e.g. fieldset 
with feature-widgets and passing an proper array of dicts to them should 
render the form correctly.

Diez

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to