Pass more than string value with autocomplete option?

Hey! As the title says I am looking for if there is a way I can collect more info about the option than just passing along a string value? My bot autocompletes a list of "tags". In the autocomplete the tag name is returned as name (duh) and the id is returned as value, so that I can filter on the relevant id in the rest of the flow. But I am interested in: 1. Being able to get the name in the rest of the flow (e.g. to give helpful error messages rather than just referring to the tag id) 2. Being able to pass more data than just a string, would be great if the autocomplete could return a value object instead Anyone know if something like this is possible to accomplish today? Any of the two would be very helpful
16 Replies
d.js toolkit
d.js toolkit•4w ago
Amgelo
Amgelo•4w ago
1. you can pass true to get the whole option
d.js docs
d.js docs•4w ago
Amgelo
Amgelo•4w ago
2. you can only pass a string, that's what the api accepts, alternatively you could just serialize and deserialize
Fredrik
FredrikOP•4w ago
Hm, I thought getFocused was only relevant in the autocomplete itself, not for the rest of the flow
Amgelo
Amgelo•4w ago
I thought you meant the autocomplete handling with "rest of the flow"
Fredrik
FredrikOP•4w ago
Ah, sorry for being unclear Let's take a real use case: 1. The user autocompletes { name: "Foo Bar", value: "123123423423" } 2. We want to send them a message saying something along the lines of "Here are the entries for Foo Bar: <list>" Currently since I am only able to access the value I get a rather anonymous (and for the user completely random value) looking message "Here are the entries for 123123423423: <list>"
Amgelo
Amgelo•4w ago
you could pass the name alongside the value as well, but in order to respond with the Foo Bar option you needed the tags (name and id) in the first place, are you not able to then use the id to look back to what tag it corresponds (and get its name)?
Fredrik
FredrikOP•4w ago
Yep, but then I need to cache it somewhere (or make the call again) as it is currently based on a database call I should probably cache it regardless, but was hoping I wouldn't need it yet
Amgelo
Amgelo•4w ago
well technically you don't need it yet either, since that's more of a convenience thing for the user :kek:
Fredrik
FredrikOP•4w ago
Fair 😅
Amgelo
Amgelo•4w ago
caching would be the best yeah once you implement that you can show the name as well
you could pass the name alongside the value as well
or do this, but you're going to eventually remove it so I'd say it isn't a good idea
Fredrik
FredrikOP•4w ago
Via e.g. json stringifying and parsing?
Amgelo
Amgelo•4w ago
or just serializing to something like name;id
Fredrik
FredrikOP•4w ago
Alright, cheers for your help! I guess I should look into some caching solution, but I don't look forward making my little hobby project into yet another place I have to debug cache invalidation problems 😂
Amgelo
Amgelo•4w ago
I just use ttl-cache or lru-cache and call it a day or LimitedCollection which is exported by djs

Did you find this page helpful?