[ 2 posts ]

John Mizliso

  • Username: abxccd
  • Joined: Sun Jan 22, 2012 11:20 pm
  • Posts: 48
  • Offline
  • Profile
Tags:

Possible to use key-value pairs with autocomplete?

Post Posted: Tue Jul 10, 2012 4:38 pm
+0-
I am using autocomplete and the multiple-value input module(http://yuilibrary.com/gallery/show/multivalue-input) to build a tagging system for tagging users.

The users are simply key value pairs:
Code:
{
  "john" : 1,
  "david" : 2,
}


I would like to be able to type a "j" and get a suggestion of "john", and in the select event's object, get access to both "john" and 1.

Currently, if I use the object above, I have to type in "john" to get a suggestion of 1, which is not what I need.

Is there anyway to do this?

Todd Smith

YUI Contributor

  • Username: stlsmiths
  • Joined: Thu Nov 05, 2009 10:03 am
  • Posts: 675
  • GitHub: stlsmiths
  • Gists: stlsmiths
  • IRC: t_smith
  • Offline
  • Profile

Re: Possible to use key-value pairs with autocomplete?

Post Posted: Tue Jul 10, 2012 8:25 pm
+0-
Seems to me like the "key value pairs" concept is a little wonky. I would refactor this by defining an array of objects that looked something like;
Code:
[ { fname:"john", userid:1}, {fname:"david", userid: 2}, ... ]
Then you can access the search field using AC's " resultTextLocator : 'fname' " setting, see AutoComplete's Locating Results.

Your "select" event handler has access to the selected item's original full Object.

I worked up a sample at http://jsfiddle.net/blunderalong/Pcjhe/, where I used one of the examples with state names, and created an array of objects.

Autocomplete is quite versatile, I suggest you read the user guide and study the examples carefully to learn all of it's capabilities.

Todd
  [ 2 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum