iain duncan <[EMAIL PROTECTED]> writes:
>> What if the options for select fields is dynamically obtained for each
>> invocation of the form?
>
> I'm still trying to figure out how to do this the best way too. What I
> want to have a happen is for the field callable class ( the one with the
> fields, subclassing widget list ) to receive a runtime object used to
> get the defaults. But as the fields are static members and not instance
> fields, I'm still not clear what the right way to do this is.
>
> If anyone can point me at an example of this it would be much
> appreciated.
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.
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---