Share feedback, ideas and get community help

Updated 3 months ago

Dynamique Buttons with Key value

Hi all, How would you handle a dynamique button list where you want to display a label but you want the id associated to the label to be set in a variable? I have implemented an API that returns an array of tuples of the id and the label such as [["0","zero"],["1","one"]].
i want the buttons to display "zero" and "one" but the selected value should be "0" or "1".
A
B
O
20 comments
This is what my API returns:
Plain Text
{
  "statusCode": 200,
  "data": {
    "workspaces": [
      [
        "director:secto10a2cikiqry74d9",
        "Alexandre Roba"
      ]
    ]
  }
}
i cannot store the array of array as an array, where I could do it with an array of string.
Attachment
Screenshot_2024-09-19_at_12.47.11.png
I tried data.workspaces but it is empty.
I would like to bind the dynamic buttons to data.workspaces, display workspaces[x][1] but store workspaces[x][0] in a variable in order to make another call using the selected 'id'.
Should i return an object and use json parsing and stringify to achevie this?
i converted the API result to a list of object but I also do not have access to the workspaces array.
Attachments
Screenshot_2024-09-19_at_13.41.52.png
Screenshot_2024-09-19_at_13.41.58.png
The only way to have access to the array and bind it to buttons is apparently to returns an array of strings. Is this correct? I will stringify the objects and parse them in a script block then... I would have never guessed that something as common to to have key/value binded to a dynamic list of buttons be so complex to do 😦
Another thing that could be usefull is to have maybe the index of the selected value in the array. then we can get the key from there.
Indeed, only string and list of strings are valid variable value in Typebot
I also have this need. It's a very useful basic improvement for those who work with arrays of variable values.
@Alex From what I understand, you would have to pollute the text of the buttons with the embedded index, and then use a script to extract it, right?
Yes. This is what I understood.
@Orsy I was thinking of using something like « 1] label » and then read the beginning of the string in order to find the index
I'm trying to do this now, in the simplest way possible, maybe with an inline script {{={{My variable}}=str.match(/^\d+/)=}} or a regex ^\d+(?=.)
to extract, but I still haven't managed to do it without using the script block. Have you managed to do this without a script?
this worked for me {{={{My variable}}=str.match(/^\d+/)=}} [NOT WORKING. SORRY]

this is work:
{{Variable}}.split('.')[0]
Thanks for sharing
IMHO this should be a built in feature. Having a dictionary with key value for mapping to buttons.
Yes, a field called "Save the answer index in variable" would be enough.
Add a reply
Sign up and join the conversation on Discord