Autocomplete and list:string

117 views
Skip to first unread message

Miguel Andrés Moya Rojas

unread,
Apr 28, 2014, 3:38:04 PM4/28/14
to web...@googlegroups.com
Hello! My issue is this: I want to use the autocomplete widget (SQLFORM.widgets.autocomplete) but my field is a list:string, and now it shows all data in only one field, resulting in an awkward input. How can I use this widget with a list:string field? Thanks in advance. :)

Johann Spies

unread,
Apr 30, 2014, 5:22:38 AM4/30/14
to web...@googlegroups.com
On 28 April 2014 21:38, Miguel Andrés Moya Rojas <miguelm...@gmail.com> wrote:

Hello! My issue is this: I want to use the autocomplete widget (SQLFORM.widgets.autocomplete) but my field is a list:string, and now it shows all data in only one field, resulting in an awkward input. How can I use this widget with a list:string field? Thanks in advance. :)


And your code is ...?

Regards
Johann

--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

Seraaj Muneer

unread,
Jan 17, 2016, 4:14:12 PM1/17/16
to web2py-users
db.define_table('company',
 
Field('name', 'string', length=20, represent=lambda name, row: name.capitalize(), required=True,
 unique
=True, notnull=True,
 requires
=[IS_NOT_EMPTY(error_message='You must enter a company name'),
 IS_MATCH
('^[a-zA-Z0-9][a-zA-Z0-9 ,-.]*$')
 
]),
 
Field('user_id', 'reference auth_user', ondelete='NO ACTION', label='User',
 writable
=False, readable=False,

 
),
 
Field('is_default', 'boolean', writable=False),
 address
,

 format
=lambda r: r.name or 'No name company')
db
.company.name.requires = IS_NOT_IN_DB(db, db.company.name, error_message='This company name is in use')
db
.company.country.widget=SQLFORM.widgets.autocomplete(request, COUNTRIES, limitby=(0,10), min_length=2)

I get 
<type 'exceptions.AttributeError'> 'tuple' object has no attribute 'tablename'

COUNTRIES is just a list of strings

Thanks 

Massimo Di Pierro

unread,
Jan 17, 2016, 8:12:44 PM1/17/16
to web2py-users
I do not see a db.company.country, although I am not sure that is the problem.

Saeed

unread,
Jan 18, 2016, 12:31:49 AM1/18/16
to web...@googlegroups.com

In fact that is the the problem. I want to fill the country widget with just a list (ordinary python list of strings) of countries so the user can select from that list.

So essentially the backing list of the auto complete isn't part of the db but just a bunch of strings in an ordinary list

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/6a4KRtDE26M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages