Hey @_andrey! Great question. The issue is that “value” means different things across different components. What’s your use case exactly - what are you trying to do with the triggering component’s value? You should be able to take the triggered by ID and just add .value in most cases.
Hi @justin!
I have 2 Editable Text components calling the same query.
Inside of this query I can get the component id (stored in the triggeredById variable).
Is there any way to get a reference to the component and read it’s value?
I can obviously do something like this:
let value = ""
if(triggeredById == "component1") value = component1.value
else if(triggeredById == "component2") value = component2.value
Is there any way to avoid the if-else?
E.g. something like this (pseudocode): triggeredById.value
Thanks!
Ah, that’s what I guessed. Yea, for now there’s no way around this unfortunately - your logic seems pretty much correct How many components are you working with here - would the if else be too unwieldy?
The best option I’ve come to with this kind of scenario is creating a “dictionary” object like this and then selecting from that using bracket notation
var value = {"eventLogs": eventLogs.value, "otherThing": otherThing.value}[triggeredById]
As a complement to this question - I have a series of components which are identified by their IDs, i.e. "name7", "name8","name9". I plan to iterate through a script with (7,8,9) as an array, which will then locate the corresponding component. For example, when the script is on 7, it will find "name7" and return the value, and so forth. Is there a way to do this programmatically? Simply concatenating "name" + [array value] as a string doesn't work, as Retool won't recognise that it should reference a component.