IS_IN_DB validator dropdown formatting

111 views
Skip to first unread message

Jim S

unread,
Feb 11, 2014, 10:57:00 AM2/11/14
to web...@googlegroups.com
I'm looking for a way to format the dropdown list generated from a SQLFORM.

I'm using the following code:

db.equipOrder.customerId.requires = IS_IN_DB(query, db.customer, ('%(customerId)s - %(name)s'), zero='..')

which give me a nice dropdown list showing my customer id and name.  However, I'd really like to add a second line to each item in my list that displays the city and state where the customer reside.  Is there a way for me to do this using the IS_IN_DB validator?

-Jim

Anthony

unread,
Feb 11, 2014, 11:07:44 AM2/11/14
to web...@googlegroups.com
I don't think you can put any additional HTML tags in an <option> element, so you would probably have to use a Javascript plugin to render a custom dropdown (e.g., http://designwithpc.com/Plugins/ddSlick).

Anthony

Jim Steil

unread,
Feb 11, 2014, 12:52:28 PM2/11/14
to web...@googlegroups.com
Thanks Anthony.  Trying this but running into a problem generating the json to use for the data.  Keep getting a javascript error:

SyntaxError:  invalid property id

On the python side I'm building it like this:

        for customer in db(customerQuery).select(orderby=db.customer.customerId):
            customerList.append(dict(value=customer.customerId,
                                     text=customer.name,
                                     description='%s, %s' % (customer.city,customer.state)))

      customerList = response.json(customerList)

then I'm passing {{=customerList}} to the data argument in the javascript.  I'm not well-versed enough in javascript/json to know how to get rid of these quotes, and even if I do, will it help?

Any insight would be appreciated.  Or, tell me to work it out on my own....

-Jim


--
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/dx_PQybY4MI/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/groups/opt_out.

Cliff Kachinske

unread,
Feb 11, 2014, 11:49:29 PM2/11/14
to web...@googlegroups.com
Have you tried simplejson.dump()?

Anthony

unread,
Feb 12, 2014, 9:41:19 AM2/12/14
to web...@googlegroups.com
{{=XML(customerList)}}


On Tuesday, February 11, 2014 12:52:28 PM UTC-5, Jim S wrote:

Jim Steil

unread,
Feb 12, 2014, 9:45:40 AM2/12/14
to web...@googlegroups.com
I've since abandoned working with ddslick for this function.  Decided just to go low tech and put the data into a single line in the IS_IN_DB dropdown.

I couldn't find a control that worked the way I'd had it working in my previous TurboGears app utilizing dojo.

I really like the ddslick widget but the default look of it didn't look right with the rest of my form.

Really appreciate the input, helped me learn quite a bit yesterday.

-Jim

Anthony

unread,
Feb 12, 2014, 10:14:26 AM2/12/14
to web...@googlegroups.com
Note, there are many alternatives to ddslick -- that's just one I found with a quick search.

Jim S

unread,
Feb 12, 2014, 12:23:37 PM2/12/14
to web...@googlegroups.com
Yes, I looked at many others as well.  But, the requirement didn't deserve that much of my time on this project.  We'll be just fine with the low-tech solution.  But, opened my eyes for possibilities on other projects.

Thanks again...

--Jim
Reply all
Reply to author
Forward
0 new messages