Problem: db field uses type='list:reference *other_table*', multiple=True. 
I need to an easy-to-use UI to search the referenced table, offer 
auto-complete and create a separate input for each selection to make 
selecting multiple options deliberate and obvious.

I started out with something along these lines:

db.define_table('book',
  Field('f_title', type='string', label=T('Title'), required=True),
  Field('f_author', type='string', label=T('Author'), required=True),
  format='%(f_title)s'
  )

db.define_table('student',
  Field('f_name', type='string', label=T('Name'), required=True),
  Field(...),
  Field('f_reports', type='list:reference book', label=T('Selected books')),
  format='%(f_name)s'
  )

Using SQLFORM, it was easy to create a form for students to enter their 
information and select one or more books they would do a report on.

Now that the book library has grown to hundreds of books, there are two new 
problems.
1) Books can be hard to find based solely on their placement in the SELECT 
according to the first letter, ("Grapes of Wrath" or "The Grapes of 
Wrath"), and 
2) Students have difficulties keeping track of what has been CMD/Ctrl 
clicked. One loose click at the bottom of the list clears previously 
selected books.

Changing db.book to the following:
db.define_table('book',
  Field('f_title', type='string', label=T('Title'), required=True),
  Field('f_author', type='string', label=T('Author'), required=True),
  Field('f_search', type='string', label=T('Searchable')),
  format='%(f_title)s'
  )

allows me to add any string that might be helpful in finding the book, such 
as author, common misspellings, subject, etc., into one searchable field. 
This gives a head-start on solving Problem #1.

Is there a way to do something similar to the form created by field type 
'list:integer/string', where multiple input fields are created as needed 
(problem #2), but with autocomplete based on search (problem #1)?

Students are allowed to select an undefined number of books, so something 
that adds fields dynamically would be much better than creating enough 
fields to cover any eventuality.

As a proof of concept, I've been using Marco Polo by Justin Stayton 
(https://github.com/jstayton/jquery-marcopolo) to create auto-completing 
fields based on search.  In the controller, I'm inserting fields to my form 
(form[0].insert), hiding all but the first option, then un-hiding them with 
jQuery when the previous has been edited.  After the form passes 
validation, then I use my inserted fields to build the list that gets saved 
to the db.

Is this my best option?  I looked at using list:integer/string, and 
SQLFORM.factory, but am not sure how to integrate with Marco Polo as the 
SQLFORM created/duplicated list input fields share the same id. ('
student_f_reports', etc).

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to