Editable Dropdown List in Web2py

45 views
Skip to first unread message

LeChef

unread,
Jun 8, 2019, 3:25:41 PM6/8/19
to web2py-users

I am new in Web2py.

I have the current requiment

I need to create a Dropdownlist where in the user can select a value from

the dropdownlist or type the value in.

The Dropdownlist values are storedin a database table.

Examplee:

my Form looks like this one:

"Where do you come from?": Dropdown lists the available cities, if your

city is not found type in your city.


I tried this code:

Field('City', requires = IS_IN_DB(db,db.city.id,'%(city)s')

With this code i can not enter a new city if it is missing in the

database.

I can only select the available cities in the database.


Full-Code:


Model:

db.define_table('city',Field('name',type='string',length=100,required=True

,notnull=True, ondelete='SET NULL',unique=True),format='%(name)s')

db.define_table('person',Field('name',type='string',length=100,required=Tr

ue,notnull=True, ondelete='SET NULL',unique=True),

Field('city_id','reference city',required=True,notnull=True,label='City'),

format='%(name)s')

db.person.city_id.requires=IS_IN_DB(db,'city.id' ,'%(city)s')

Controller:

def person(): return dict(grid=sqlform.grid(db.person,create=True,editable=True,deletable=True))

View:

{{extend 'layout.html'}} ... <div class="row"> <div class="col-md-12"> {{pass}} {{=grid}} </div> </div>
Reply all
Reply to author
Forward
0 new messages