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
-~----------~----~----~----~------~----~------~--~---

Reply via email to