Cecil Westerhof wrote:
> I am trying to work with a SingleSelectField in a WidgetsList in a 
> TableForm.
> When I have the following in the WidgetsList:
>     owner         = SingleSelectField(name    = 'Eigenaar',
>                                       options = ownerOptions,
>                                       default = 3)
>
> The right default value is displayed, but the field is not updated. 
> This because the save function is called with a value for 'Eigenaar' 
> and not for 'owner'.
> The values given to the save function:
>     {'afternoonFood': u'dinner', 'notes': u'Wil graag geknuffeld 
> worden', 'description': u'middelgrote bruin/witte vuilnisbak', 'name': 
> u'Pedro', 'eveningFood': None, 'Eigenaar': 3, 'morningFood': u'brokken'}
>
> When I have the following code:
>     owner         = SingleSelectField(name    = 'owner',
>                                       label   = 'Eigenaar',
>                                       options = ownerOptions,
>                                       default = '3')
> I can update the owner field, but there is no default set and 
> initially the first value is always displayed.
> The values given to the save function:
>      {'afternoonFood': u'dinner', 'notes': u'Wil graag geknuffeld 
> worden', 'description': u'middelgrote bruin/witte vuilnisbak', 'name': 
> u'Pedro', 'owner': 3, 'eveningFood': None, 'morningFood': u'brokken'}
>
> What do I need to do to get the right default and have the possibility 
> to save the owner. One possibility is offcourse to set the value of 
> 'owner' to the value of 'Eigenaar in the save function, but I expect 
> that there is a better way.
>
>
> The complete class:
> #####
> class DogFields(WidgetsList):
>     name          = TextField(label     = 'Naam *',
>                               validator = validators.NotEmpty)
>     description   = TextField(label     = 'Omschrijving')
>     sex           = EnumCol(  label     = 'Geslacht')
>     morningFood   = TextField(label     = 'Ochtendvoer')
>     afternoonFood = TextField(label     = 'Middagvoer')
>     eveningFood   = TextField(label     = 'Avondvoer')
>     notes         = TextField(label     = 'Opmerkingen')
>     owner         = SingleSelectField(label   = 'Eigenaar',
>                                       name    = 'owner',
>                                       options = ownerOptions,
>                                       default = 3)
> #####
>
> Function to fill options:
> #####
> def ownerOptions():
>     return [(-1, 'Selecteer Eigenaar')] +\
>            [(entry.id <http://entry.id>, entry.firstName +\
>              ' ' + entry.lastName +\
>              ' uit ' + entry.place) for entry in Owner.select()]
> #####
>
> code in the edit function:
> #####
>     record = Dog.get(int(id))
>     form = TableForm(
>         fields = DogFields(),
>         method = 'POST'
>     )
>     values = dict(owner = record.owner, Eigenaar = record.owner)
>     return dict(form   = form,
>                 page   = 'edit',
>                 record = record,
>                 table  = table,
>                 values = values)
> #####
>
> I would like to have record.owner as the default instead of the 
> hardcoded 3. How do I do that?
>
> -- 
> Cecil Westerhof
> >
Cecil:

In my opinion, you should be setting your default using your controller, 
and not in the widget definition.  Separate the logic from the display 
definition.

    -Jim


--~--~---------~--~----~------------~-------~--~----~
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