On Wednesday 22 August 2007 16:05:18 Jim Steil wrote:
> Hi
>
> I'm having a problem with a SingleSelectField. It's probably more of a
> problem with my understanding of when things are loaded, but I was
> hoping someone could explain this to me a bit.
>
> I have the following form:
> ------------------------------------------------
> class FormFields(WidgetsList):
> name = TextField(label='Name:', validator=validators.NotEmpty)
> district = SingleSelectField(label='District:',
> options=qOptions.getDistrictOptions('None'),
>
> validator=validators.All(validators.NotEmpty(), validators.Int()))
> testForm = TableForm(fields=FormFields(), submit_text='Save Changes')
> ------------------------------------------------
> And, I have the following method to fill the SingleSelectField in the
> qOptions module:
> ------------------------------------------------
> def getDistrictOptions(allNone='None'):
> ds = District.select(orderBy='name')
> options = [('', '-- %s --' % (allNone))]
> for d in ds:
> name = d.name
> if d.salesman:
> name = '%s - %s' % (name, d.salesman.display_name)
> options.append((d.id, '%s' % (name)))
> return options
> ------------------------------------------------
> This works fine, except if I make a change to the salesman assigned to a
> district. If I do, I still get the old salesman name in the dropdown
> even though it has been changed. If I restart the server I then get the
> correct salesman name. I use this pattern all over in my application,
> but without the foreign key lookup and getting the name from the related
> table. In these SingleSelectFields, changes to the table takes effect
> immediately and doesn't require a restart.
>
> Can someone help me understand why this is happening?
Because you don't pass a callable as you should.
name = TextField(label='Name:', validator=validators.NotEmpty)
district = SingleSelectField(label='District:',
options=qOptions.getDistrictOptions,
validator=validators.All(validators.NotEmpty(), validators.Int()))
should do the trick.
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
-~----------~----~----~----~------~----~------~--~---