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'),
)
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/64655170-786e-4d3d-bd39-6d2fa75f89c5n%40googlegroups.com.