Almost straight from the book but using my own db fields - tested and works...
This controller in default.py
def from_factory():
form = SQLFORM.factory(Field('your_name', requires = IS_IN_DB(db,db.person.id,'%(first_name)s')))
if form.process().accepted:
response.flash = 'form accepted'
session.your_name = form.vars.your_name
elif form.errors:
response.flash = 'form has errors'
return dict(form=form)
with this view 'from_factory.html'
{{extend 'layout.html'}}
{{=form}}
gives a drop down list of person's first_names.
The selected name is now held in the cookie 'session.your _name'
but if you want the table id then,
replace... session.your_name = form.vars.your_name
with something like ... session.person_id =
form.vars.idHope this helps.
Peter
[edit]
Sorry I notice you are looking for something a little more complex so here is something I put together with help!
I'm not saying it is ideal or perfect but the logic worked for me...
I added a lazy field at the end of a table that calls a function to build the required dropdown view I wanted...
e.g.
db.person.display_name = Field.Virtual('display_name',
get_person_display_name)
def
get_person_display_name(row):
if row.person.person_type == 'CLIENT':
if row.person.referrer_ref:
display_name = '%s %s' % (row.person.referrer_ref, row.person.first_name)
else:
display_name = 'PAP/%s %s' % (
row.person.id, row.person.first_name)
elif row.person.person_type == 'CONTACT':
display_name = '%s, %s' % (row.person.last_name, row.person.first_name)
return display_name
but I am beginning to understand the problem more with the dependency on INPUT helper for js
given that
"input tag has an optional attribute _type that can be set to "text" (the default), "submit", "checkbox", or "radio"."
non of which is a drop down obviously...
I did try the various _types in...
{{=INPUT(_type='text',_name='mychoice', requires = IS_IN_DB(db,db.person.id,'%(first_name)s'))}}
it doesn't complain but it doesn't do what you want either
.
Sorry if I have wasted your time!