When using SQLFORM to update list:reference fields, the select input
does not show the database value as selected.  It shows the zero value
instead.  If I remove the zero value, it just shows a blank line.

Here is my code.  What am I doing wrong?

model:
db.define_table('owners', Field('name'))
db.define_table('dogs', Field('doggiename'), Field('owner',
'list:reference owners'))
db.dogs.owner.requires = IS_IN_DB(db, db.suppliers.id, '%(name)s',
zero='Choose')

controller:
def action():
    if request.args(0):
        form=SQLFORM(db.dogs, request.args(0))
        msg = 'Dog record updated.'
    else:
        form=SQLFORM(db.products)
        msg = 'Dog record saved.'
    if form.accepts(request.vars, session):
        response.flash = msg
    elif form.errors:
        response.flash = 'Please correct the form'
    return dict(form=form)

I know how to hand hack a form using FORM, SELECT and OPTION, but I
would much rather use SQLFORM.

Caveat: field and table names changed for clarity.

Thanks,
Cliff Kachinske

Reply via email to