Jorge Godoy wrote:
> This one's easy to answer.
>
>
> The only question you should as is:
>
> Are my <field> options dependent on some previous choice made on the same
> form? (e.g. countries -> states, states -> cities)
>
> NO
>
> Use a callable to populate the field
>
> YES
>
> Use AJAX to populate the field.
>
>
> You'll always have a method that will return the options based on some filter
> (possibly with default values) and that can be exposed through JSON or not.
>
>
> For the example above:
>
> @expose('json') # Just if using AJAX...
> def my_states(self, country=None):
> return self._my_states(country)
>
>
> # This version can be used inside the application, without the JSON armor
> def _my_states(self, country=None):
> states = model.State.select()
> if country is not None:
> states = states.filter(model.State.q.country = country)
> return dict(states = states)
>
>
> my_widget = widgets.SomeWidget(
> ...
> options = self._my_states(default_country)
> ...
> )
>
>
>
> The AJAX code depends on your widget, your other fields, etc. You'll find
> lots of examples on the archives and googling for them.
>
OK, that's great. I've tested that with statically declared forms and it
seems to work OK. Just the DatePicker's date format to get around then :)
One more question if I may. How to change the attributes of statically
declared form fields at runtime. I need to set some fields to readonly
or change the maxlength of a TextField for example. What's the best way
to do this per request?
Thanks for your help,
Gary.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---