react-typeahead
react-typeahead copied to clipboard
Use of key/value paired objects in the options list
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!
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.
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.
I deferred to letting #35 run it's course, no need to re-invent the wheel.
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.
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.
I've opened #61 to revive #35 with some further options/convenience methods.
:+1: is a must. the plugin is incomplete without this