autocomplete basic confusion

75 views
Skip to first unread message

Phil Hughes

unread,
Mar 14, 2015, 5:33:13 PM3/14/15
to web...@googlegroups.com
I seem to be in a loop (me, not the computer) getting autocomplete to do what I want which is totally basic. I have reduced this to a test case and could use a push in the right direction. (Consider this one of my 20 variations.)
What I want is for the reference lookup to use nombre (not the ID field) in autocomplete.

Thanks.

MODEL
db.define_table('stuff',
                Field('nombre', 'string', requires=IS_NOT_EMPTY())
                )

db.define_table('reel',
                Field('whatever', 'string', requires=IS_NOT_EMPTY()),
                Field('sid', 'reference stuff')
                )

CONTROLLER
def stuff():
    grid  = SQLFORM.grid(db.stuff, user_signature=False)
    return locals()

def reel():
    grid = SQLFORM.grid(db.reel, user_signature=False)
    db.reel.sid.widget = SQLFORM.widgets.autocomplete(
      request, db.reel.sid, id_field=db.stuff.nombre)
    return locals()


Niphlod

unread,
Mar 15, 2015, 6:43:34 AM3/15/15
to web...@googlegroups.com
uhm. just one sec.... let's get back to the beginning ......reference fields support is for storing the primary key of the referenced table.... if you define things as you did, you'll get db.reel.sid with an id pointing out to the 'stuff' record whose id is that one. this seems to clash with the "what I want" statement you exposed..... please clarify what you want stored in tables before continuing....

Phil Hughes

unread,
Mar 15, 2015, 9:07:54 AM3/15/15
to web...@googlegroups.com
It is correct thatt I want stuff.id in the table. But, I when entering the data I want to have an auto-complete list of values of nombre to select from.

On Sun, Mar 15, 2015 at 4:43 AM, Niphlod <nip...@gmail.com> wrote:
uhm. just one sec.... let's get back to the beginning ......reference fields support is for storing the primary key of the referenced table.... if you define things as you did, you'll get db.reel.sid with an id pointing out to the 'stuff' record whose id is that one. this seems to clash with the "what I want" statement you exposed..... please clarify what you want stored in tables before continuing....

--
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/OYly9gV1GHA/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.



--
Phil Hughes
nic...@gmail.com



Niphlod

unread,
Mar 15, 2015, 9:25:53 AM3/15/15
to web...@googlegroups.com
uhm........then you completely skipped the docs about the autocomplete widget...

model
db.define_table('stuff',
               
Field('nombre', 'string', requires=IS_NOT_EMPTY()),
                format
='%(nombre)s'

               
)

db
.define_table('reel',
               
Field('whatever', 'string', requires=IS_NOT_EMPTY()),
               
Field('sid', 'reference stuff')
               
)



controller

def reel():
    db
.reel.sid.widget = SQLFORM.widgets.autocomplete(request, db.stuff.nombre, id_field=db.stuff.id)
    grid
= SQLFORM.grid(db.reel, user_signature=False)
   
return locals()



Leonel Câmara

unread,
Mar 15, 2015, 9:44:26 AM3/15/15
to web...@googlegroups.com
Notice that the important difference is in the order. Niplhod set the widget for the field before calling SQLFORM.grid.

Phil Hughes

unread,
Mar 15, 2015, 9:47:40 AM3/15/15
to web...@googlegroups.com
Well, I didn't skip them but clearly I was in that loop I talked about.
Thanks.

--
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/OYly9gV1GHA/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.



--
Phil Hughes
nic...@gmail.com



Niphlod

unread,
Mar 15, 2015, 9:48:07 AM3/15/15
to web...@googlegroups.com
on top of that, the autocomplete was set to autocomplete based on the values presented on the reel table instead of the - wanted - stuff table....

Phil Hughes

unread,
Mar 15, 2015, 10:11:00 AM3/15/15
to web...@googlegroups.com
The order had perviously been correct. I probably should have included my initial try after reading the docs. It was a bit closer.

Thanks. All is well now.

On Sun, Mar 15, 2015 at 7:44 AM, Leonel Câmara <leonel...@gmail.com> wrote:
Notice that the important difference is in the order. Niplhod set the widget for the field before calling SQLFORM.grid.

--
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/OYly9gV1GHA/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.



--
Phil Hughes
nic...@gmail.com



UG

unread,
Mar 16, 2015, 9:41:58 AM3/16/15
to web...@googlegroups.com

Hi,
I am not sure i follow your question 100%. Is this what you need?

db.define_table('stuff',
                Field('nombre', 'string', requires=IS_NOT_EMPTY()),               

                format='%(nombre)s')

              

Reply all
Reply to author
Forward
0 new messages