SQLFORM.factory and autocomplete widget

704 views
Skip to first unread message

david.waldrop

unread,
Oct 17, 2010, 10:58:28 AM10/17/10
to web2py-users
I have a form created with SQLFORM.factory containing a single field

addform = SQLFORM.factory(Field('item_cat'))

Is there a way to use the autocomplete widget. I have searched and
seen examples where I set the widget in the model, but do cannot find
an example of how to associate the autocomplete widget with a field
when using SQLFORM.factory.

I did get it to work in the model bu using something like the
following: db.itemcat.cat_ref.widget =
SQLFORM.widgets.autocomplete(request, db.cat.name, id_field=db.cat.id)

I am sure someone has done this and very much would love to see an
example.

david.waldrop

unread,
Oct 17, 2010, 2:24:05 PM10/17/10
to web2py-users
I have now tried this

addform =
SQLFORM.factory(Field('item_cat'),widget=autocomplete(request,
db.cat.name, id_field=db.cat.id) )

but it doesn't work either.

mr.freeze

unread,
Oct 17, 2010, 3:49:51 PM10/17/10
to web2py-users
You need to pass the widget the the Field constructor, not the
SQLFORM.factory constructor.

david.waldrop

unread,
Oct 17, 2010, 3:50:41 PM10/17/10
to web2py-users
some minor progress. The following now lets thge loaded component
work, but does not do the autocomplete .

addform =
SQLFORM.factory(Field('item_cat'),widget=SQLFORM.widget.autocomplete(request,
db.cat.name, id_field=db.cat.id) )

Is there something special I need to do to get the autocomplete to
work inside a loaded component?

mdipierro

unread,
Oct 17, 2010, 4:13:05 PM10/17/10
to web2py-users
SQLFORM.factory(Field('item_cat'),widget=SQLFORM.widget.autocomplete(request,
db.cat.name))

or

SQLFORM.factory(Field('item_cat',db.cat),widget=SQLFORM.widget.autocomplete(request,
db.cat.name, id_field=db.cat.id) )

david.waldrop

unread,
Oct 17, 2010, 6:59:05 PM10/17/10
to web2py-users
Thanks for the suggestions. I tried both, but I still cannot get it to
work. I think I have it isolated to the fact that the textbox i am
trying to use autocomplete on is loaded in a view using the LOAD
command. In fact it is the technique I am using is identical to the
tagging widget. IS it possible to use the autocomplete widget in this
manner?

On Oct 17, 4:13 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> SQLFORM.factory(Field('item_cat'),widget=SQLFORM.widget.autocomplete(reques t,
> db.cat.name))
>
> or
>
> SQLFORM.factory(Field('item_cat',db.cat),widget=SQLFORM.widget.autocomplete (request,

mdipierro

unread,
Oct 17, 2010, 7:03:35 PM10/17/10
to web2py-users
Probably not. ajax calls do not execute JS embedded in loaded content.

david.waldrop

unread,
Oct 17, 2010, 7:08:14 PM10/17/10
to web2py-users
do you have any suggestions I can research/try for another approach to
get the needed functionality?
Reply all
Reply to author
Forward
0 new messages