Hello again. Good news (for me anyway), I figured out what I was doing
wrong. In the search_username method I had to pass the value of the ID
back. Here is what I did:
OLD VERSION
@tg.expose(allow_json=True)
def search_username(self, search):
matching_users =
User.select(User.q.display_name.startswith(search.encode('utf8')))
usernames = [user.display_name for user in matching_users]
return dict(usernames=usernames)
NEW VERSION
@tg.expose(allow_json=True)
def search_username(self, search):
matching_users =
User.select(User.q.display_name.startswith(search.encode('utf8')))
usernames = [(user.display_name, user.id) for user in
matching_users]
return dict(usernames=usernames)
Now my only remaining problem is the cursor control using the arrow keys.
Is there something I need to do to get the cursor placed on the first row of
the list of results so that I can arrow through it?
-Jim
_____
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jim Steil
Sent: Tuesday, January 16, 2007 12:25 PM
To: [email protected]
Subject: [TurboGears] Re: AutoCompleteField help
Jorge: I tried what you said below, but both my hidden field and the
displayed field show the same value, the value I was searching on. Do I
need to set a parameter to force it to bring back the ID field somehow? My
code looks like this:
class DeleteUser(WidgetsList):
username =
AutoCompleteField(search_controller="/formula/search_username",
search_param = 'search',
result_name = 'usernames')
task_form = TableForm(fields=DeleteUser())
In the controller I have:
@tg.expose(template='motion.templates.formula.test')
def test(self, *args, **kw):
import time
try:
userid = kw['username']['hidden']
except:
userid = 'None'
tg.flash(userid)
submitAction = '/formula/test'
return dict(now=time.ctime(), menuLinks=self.menuLinks,
widget=widgets.task_form, action=submitAction)
@tg.expose(allow_json=True)
def search_username(self, search):
matching_users =
User.select(User.q.display_name.startswith(search.encode('utf8')))
usernames = [user.display_name for user in matching_users]
return dict(usernames=usernames)
Also, another problem I've noticed is that when I start typing in my name I
get the dropdown to list those that matched what I've typed. However, the
first row of the list is never selected. I can't select it with my arrow
keys, but have to click on it with my mouse. Any idea why?
-Jim
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jorge Godoy
Sent: Monday, January 15, 2007 11:24 AM
To: [email protected]
Subject: [TurboGears] Re: AutoCompleteField help
"Jim Steil" <[EMAIL PROTECTED]> writes:
Im working with the AutoCompleteField widget and have it working just
fine.However, what Im really trying to do is to get an ID returned to me
for the field Im selecting.What Im trying to do is allow the user to
start typing in a Customer name and then select it from the autocomplete
list that is presented. But, when they click on a Customer name in the
list, I want it to return the ID of the customer and not the customer
name.Has anyone extended the AutoCompleteField widget to do this already?
Please tell me if you think this is a bad idea or the wrong way to get
this
information. Any input is appreciated.
It already does that. You have two fields, being one of those hidden. By
default the hidden field will have the id of what is being shown. (Actually
it can have anything, but both fields are tied together by the same option
chosen.)
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---