Single Choice input capture: Can choices be deriv...
# 🤝help
w
I have an array variable whose contents I would like to appear as choices in a Single Choice input card. However, when I use the
{x}
control in
Items
to add choices via variable, the error
Error: object type is not allowed: array type
is given. Is there a way to generate input choices from an existing array variable? I checked the docs, but this topic does not appear to be addressed
n
I believe it is. How do you have the fields right now in the single choice cards to access each of the array elements?
a
Hey @wonderful-wolf-37241, you can use an array to display single choice options. Keep in mind items in the array need to be objects of the following structure
Copy code
{ label: "Some option", value: "1" }
w
@aloof-traffic-22451 Thanks a bunch for that information! I just tried that exact structure with a test variable's default value, but the Single Choice card shows a different error that is cut off (+ non-selectable) and I can only read the first line -- it starts
array type is only allowed
...-- I tried with the array var type set both as
options
and as
string
, same result -- do you happen to know what the full text of that error is supposed to be? // screenshot of error attached ( @User this is the the
{x}
field setup in the Single Choice card https://cdn.discordapp.com/attachments/1245149272412913764/1245448436917207164/botpress-array-var-single-choice-error.png?ex=6658c9be&is=6657783e&hm=812271c9c9d6c73b7e18c8071565ad67a94d22a172bf2b618c8b128e1926fe48&
a
@wonderful-wolf-37241 Could you please confirm testArray is actually of type array?
If that's not the issue, please send me report id @square-energy-41150
s
# Sending a Problem Report Here's how to send the Botpress Team a problem report: 1. In the Botpress Cloud Studio, locate the "Help" icon in the bottom left corner of the screen. 2. Click "Report a problem" and follow the steps on the screen. 3. Copy the Report ID to your clipboard and provide it to a member of the Botpress Team on Discord.
message has been deleted
@aloof-traffic-22451 report ID is:
report_01HZ2WT57V0C4Z59AFM6WHKRR9
a
w
Aha! The
schema
/
{x}
input doesn't want the double curly braces around the var name, that was the problem! I was putting them in there because some other interface elements (e.g. text card, etc) that are marked with the
@
want the double curly braces (if the
@
is not used). Removing the double curly braces solved the problem and produced the expected behavior. Thanks very much for your kind help @aloof-traffic-22451 !
It looks like the "Array type" control is gone from the variable setup dialog -- is there some other setting that needs to be done to make an array var accessible as single choice options, or should a standard array var now work, provided the objects populating it are in the
{label:"foo",value,"bar'}
format?
UPDATE: I just monkeyed with it myself until I figured it out -- the current
array
type will handle these options with no modification, and the single choice card will process the array as expected, given that the objects in the array conform to the above format, and no curly braces are used in the single choice card's
{x}
control (that is, the variable should be entered into that field without surrounding curly braces}
g
@wonderful-wolf-37241 Can you please share the final input for items
workflow.options=[{label:"foo",value:"bar"},{label:"ali",value:"ali"}]; and using worflow.options as input for items
w
@great-insurance-89011 your array is constructed correctly as far as I can tell.
23 Views