Clarification please on autocomplete widget...

31 views
Skip to first unread message

jim kaubisch

unread,
Jun 18, 2018, 11:59:27 PM6/18/18
to web2py-users
What am I misunderstanding... ??

Building a form with fields that really need to be autocompleted (potentially 1,000+ possible values)

Looked at the book which says "two possible uses for the autocomplete widget: to autocomplete a field that takes a value from a list or to autocomplete a reference field"
I assumed that "list" meant an ordinary Python list object, but when I try:

  fields = []
  ...

 name_list = ['name1', 'name2']
  fields.append(Field('school', 'string' , label=T('School Name?')
                                         , widget=SQLFORM.widgets.autocomplete(request , name_list, limitby=(0,10), min_length=0)
                                         , requires=IS_NOT_EMPTY()))
   ...

  enter_data_form=SQLFORM.factory(*fields, table_name='enter_data')

I get the following:
        <type 'exceptions.AttributeError'> 'list' object has no attribute 'tablename'

which I interpret to mean that 'list' in this case means something different than I expected.

What am I doing wrong?

Thanks


Anthony

unread,
Jun 19, 2018, 7:05:08 AM6/19/18
to web...@googlegroups.com
No, as the example in the book shows, by "list", it just means a list generated from the contents of a single field in a database table (in contrast to the reference field option, which submits integer ID values from a reference field but searches and displays the corresponding values from an alternative field).

There are other autocomplete widgets you can use, but if you really want to use the web2py widget, I suppose you could just put your list in a database table.

Anthony

jim kaubisch

unread,
Jun 19, 2018, 11:24:07 AM6/19/18
to web2py-users
Thanks, Anthony.

because there may be MANY values in the field, what I would actually be perfectly happy with is a list as you describe it, 
but one that is the result of a db query, 

    e.g. a list of names of all schools whose "Field('district_id'   , 'reference districts', label=T('District')" is 2. 

Tried doing that yesterday without success. 

Anthony

unread,
Jun 19, 2018, 2:28:41 PM6/19/18
to web2py-users
It sounds like you want the reference field version of autocomplete. What is your exact model code and the widget code you tried?

Anthony
Reply all
Reply to author
Forward
0 new messages