Hi,
Considering the sample code below.
I have manually populated the books table with a number of books for different genres.
Now I can create an entry in the shelves table, using the SQLFORM.grid
The shelve_items will be shown as a dropdown list with the books that I've added
What I would like is to update the contents of the shelve_items dropdown list in the form, based on the selected genre in that same form.
In the past I did something similar, using a SELECT() box and adding an onchange=ajax(...) call to update a DIV elsewhere in the page.
I was wondering however, if there is a better way to do this directly in the SQLFORM.grid()
===========
index.html
===========
{{extend 'layout.html'}}
{{=form}}
===========
default.py
===========
def index():
form = SQLFORM.grid(db.shelves, user_signature=False)
return dict(form=form)
======
db.py
======
genres = ['thriller', 'sf', 'roman', 'fantasy']
db.define_table('books',
Field('name', 'string'),
Field('author', 'string'),
Field('genre', 'string', requires=IS_IN_SET(genres)),
format='%(name)s'
)
db.define_table('shelves',
Field('genre', 'string', requires=IS_IN_SET(genres)),
Field('shelve_items', 'reference books'),
)