Thanks Massimo,

Nothing is actually wrong with Val, it's a float obtained from a row.
After a fair bit of ploughing, I found that the issue is to do with
the list of [OPTION...] for the SELECT control.
If you generate a list of [<OPTION>,....] from a function like I did,
and reuse that list in multiple SELECT() calls, it gets modified as
you go:

def GenerateTimeIncrements(hours):
    return [OPTION( '%s' % v , _value=v) for v in range(hours)]

def SomeController():
    ....
    Values = GenerateTimeIncrements(10)
    table = TABLE()
    table.append(TR(TD(SELECT(value=1, *Values))))
    table.append(TR(TD(SELECT(value=2, *Values))))
    table.append(TR(TD(SELECT(value=3, *Values))))
    ....

In this case, all three drop-downs will have their default value set
to 3.0, as Values is being changed by the call to SELECT() where it
specifies which option is selected. To get what you want, you need to
do something like this:

    table.append(TR(TD(SELECT(value=1, *GenerateTimeIncrements(10)))))
    table.append(TR(TD(SELECT(value=2, *GenerateTimeIncrements(10)))))
    table.append(TR(TD(SELECT(value=3, *GenerateTimeIncrements(10)))))

I know this is down to the fact in python, a list is an object and
passed around as such (which is one of my pet peeves with the
language) but I think that in this case the desired behaviour would be
for SELECT to take a copy of the list, and avoid these issues.

Curiously, the following still causes the error, and this is the
worrying part as this is not how python should work:

    table = TABLE()
    Values = GenerateTimeIncrements(10)
    table.append(TR(TD(SELECT(value=1, *list(Values)))))
    table.append(TR(TD(SELECT(value=2, *list(Values)))))
    table.append(TR(TD(SELECT(value=3, *list(Values)))))

Any reason why this should be this way?

On Mar 14, 7:19 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> There is nothing wrong in this code. Look into the value returned by
>
>  Val = TSE[field]
>
> I think it may not contain what you think it does. I do not know why.
>
> On Mar 14, 10:33 am, Andrew Buchan <andyha...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > In my timesheet application I have a form which looks like a
> > spreadsheet, where each cell has a drop-down list of time-measures in
> > 15min increments up to 9 hours, the idea being for the user to set the
> > time he works against each job on the timesheet. The function below
> > generates these "Hours Input Cells", and works fine except that it
> > won't set the selected option to the value as obtained from the
> > assignment to Val in the second line of code.
>
> > HOWEVER, if I assign a new value to Val (see commented-out line), then
> > it selects the drop-down option to that value for each cell...
> > Note that I am obtaining a valid value for Val, I can display it in
> > the form for testing purposes (see TD in last line), and if when I
> > assign one of those values to Val as per the commented-out line, it
> > correctly sets it as selected in the drop-down list.
>
> > def HoursInputCell(TSE, field):
> >     Val = TSE[field]
> >     FieldName = GetHoursCellName(TSE, field)
> >     Values = DayTimeIncrements
> >     #Val= 2.5
> >     return TD( Val , SELECT(value=Val , *Values, _name=FieldName,
> > _width='20', _class='TimesheetHoursInput'),
> > _class='TimesheetTableDayCell')
>
> > Could this have anything to do with cache?

Reply via email to