At this moment I am doing this for a multiselect form page:

db.py:

db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
r: '%s %s' %
(db.application[r.app].name,db.server[r.server].hostname))
#table constraints:
db.instance.app.requires = IS_IN_DB(db, db.application.id, 'application.name')
db.instance.server.requires = IS_IN_DB(db, db.server.id, '%(hostname)s')

db.define_table('audienceInstances', Field('instances','list:reference
instance'),Field('user',db.auth_user,writable=False, readable=False))

default.py:
   monitoredInstances =
db.audienceInstances(db.audienceInstances.user == auth.user.id)
   #If the result of this query is None means that the user has just registered
   if (monitoredInstances == None):
       #and we insert a record with an empty list of monitored instances
       db.audienceInstances.insert(user=auth.user.id)
       #we recover the record that has just been inserted
       monitoredInstances =
db.audienceInstances(db.audienceInstances.user == auth.user.id)
       #response.flash = 'new user row inserted'

   #Generates a form for the updation of the list of monitored instances
   instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
submit_button='Update', showid=False)
   if instancesForm.accepts(request.vars, session):
       response.flash = 'list updated'
   elif instancesForm.errors:
       response.flash = 'form has errors'

in index.html:
{{=instancesForm}}

And the result is a multiselect list having as content the list of
instances. The user can edit the selection and update which are the
instances that like to have monitored.

I'd like to redesign the use case.

having an autocompletion box with a +/Add button next to it, that
allow the to add the instance visualized in the textbox after clicking
the +/Add button  to the instances field of the audienceInstances
table, instead of presenting the whole list of instances which are
more than 100 in general to the user.

When the user clicks the add button the instance selected is saved
into the database and the content of the list below should be updated.
At the same time, i'd like to add a -/remove button next to each
instance in the bottom list, to remove the instance from instances
field of audienceInstances table and remove the item from the bottom
list.

this would be a sketch up:

Select the instance to add:

|      the instance is fetched as you type with autocomplete
 |   | +/Add button|

List of monitored instances aka bottom list:
 the content of the instances list of audienceInstancesTable
-------------------------------------------
|         instance1                          |   |    - / remove            |
|         instance 20                       |   |    - / remove            |
|                                                    |
|------------------------------------------|

Is it feasible to implement this keeping the same database structure
as the existing multiselect?
Any ideas?

Thanks in advance,
Nico

Reply via email to