TokenInputRow could handle existing values better

Justis R

Member
Affected version
v2.2.7 Patch 1
The tokeninputrow href expects a response mapping an id to a display text for a provided query, when the tokeninputrow is submitted, the id is what's submitted, not the display text, which is ideal. However, the tokeninputrow only accepts a comma separated list of strings as the value, and those strings are used as both the id and display text for the filled in values, meaning that the id and display text must be the same, if you're filling in existing values.

This is a particularly severe limitation for tokens which could have a comma in their name.
For instance, resources. The tokeninputrow is the best input type to use for resources given that it is scalable to any number of resources that a user may have. A user can type in the name of their resource and find it without having to scroll through potentially hundreds of resource titles in a fully rendered checkbox/select row looking for it. However, resource titles could have commas in them, so the resource id is absolutely necessary as the token id. Which means that the tokeninputrow is effectively unusable for resources in an edit form, unless you want users seeing raw resource ids in place of their previously entered values.

Suggestion:
Accept an array as an alternative value type, and use the keys as the id and the value as the text
 
Last edited:

Justis R

Member
@Kirby Tagging you since you liked this thread, so I assume you had the same issue as I did.

Turns out you can fill in the list-data property with a json map, to supply an id => name mapping for pre-existing values.
What tripped me up, is that you also need to fill in the value property with the same ids. I had tried supplying the existing values using both properties individually, but not together. I suppose it didn't occur to me to supply the ids twice.

Code:
value="1,2"
list-data="{$associativeArray|json}"

Thank you for your time.
 
Top