react-typeahead icon indicating copy to clipboard operation
react-typeahead copied to clipboard

Use of key/value paired objects in the options list

Open soen opened this issue 9 years ago • 7 comments

Hi,

I would like to provide the tokenizer options prop with an array consisting of key/value paired objects, like: [{name: "MyName", value: "123"}]. However, I only want to display the name property of my object in the tokenizer, would that be possible? That said, I would still like to receive the full object when selecting or removing it from the tokeziner.

Thanks!

soen avatar Apr 09 '15 08:04 soen

Hey @soen . @georgwiese was working on a PR (#35) to basically implement this feature. You could try to pick it up and run with it if you're up for it, but it looks like there are some conflicts.

fmoo avatar Apr 09 '15 08:04 fmoo

Hey @fmoo - awesome, will look more into it. I can also see that @raysuelzer has started an implementation (https://github.com/fmoo/react-typeahead/issues/40). I'll check how far he is along.

soen avatar Apr 09 '15 09:04 soen

I deferred to letting #35 run it's course, no need to re-invent the wheel.

raysuelzer avatar Apr 09 '15 13:04 raysuelzer

As a quick workaround, I used the onTokenAdd callback to call a custom handler. Basically, map your [ {name: "MyName", value: "123"}, {name:"MyName2", "value":"456"}] to a new array containing only the [ "MyName", "MyName2" ] values and use it for the "options" property. Then make a function handleTokenAdd: function(tokens) {...} that retrieves the original objects and returns that to your state.

thehuey avatar Apr 09 '15 17:04 thehuey

Hi all,

I'm not sure whether I'll find time any time soon to work on the PR, unfortunately. Feel free to take this as a base and work on it, if you need the feature soon.

georgwiese avatar Apr 11 '15 07:04 georgwiese

I've opened #61 to revive #35 with some further options/convenience methods.

seansfkelley avatar Apr 15 '15 19:04 seansfkelley

:+1: is a must. the plugin is incomplete without this

cmnstmntmn avatar May 06 '15 14:05 cmnstmntmn