On Monday 29 October 2007 04:18:51 jthibeaux wrote:
> I am fairly new to Turbo Gears, and am trying to work out how best to
> deal with a form that is generating according to values in a database
> -- i.e. I do not know what fields will be there until the a database
> query is performed, and the types of fields may vary as well.
>
> In the examples I have seen, it appears that the field set for forms
> is established early on, and typically only the values are set at
> render time. More importantly, when considering validation, it seems
> that all the member_widgets and form fields are set at the class
> level, so the form validation process seems dependent on having the
> member_widgets set up front.
>
> Granted, I am sure there are lots of ways to solve this problem, but
> what I am trying to gather is what way would still leverage the form
> validation/widget handling that turbo gears offers. Is there a
> typical way to approach this problem? Have I missed something simple
> that makes this easy?
Most of the times, the static approach TG usually takes is preferable because
you lose the overhead of widget instantiation.
But it's perfectly legal & possible to move the form-building code into your
controller method and thus return a dynamically build form.
The only "issue" there is the validation. If you are ok with a session-based
approach, you could
- create a dynamic form in a controller
- stick it in the session
- return & render it
- in your action-method, define the @validate-decorator as this:
@validate(form=get_form_from_session)
where get_form_from_session looks like this:
def get_form_from_session(*args): # don't know if it get's any, see for
yourself
return cherrypy.session['my_form_key']
Then everything should work as "in the book".
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
-~----------~----~----~----~------~----~------~--~---