Dropdown multiple and IF / ELSEIF

Hello all :slight_smile:

I have this dropdown choice and i search a way for use IF or ELSEIF for showing text.

If i select one choice, i show a text. If i check multiple choices i show other text.

Big thanks all

{formmenu: default=choice1; choice2; choice3; name=choices; multiple=yes; formatter=items -> join(items, "BLAZE_AND")}

Hi @Frenchy_Devs,

To insert the desired text, you can utilize the if-else statement as shown in the provided snippet. Here I have used two things:

  1. count function to get the count of selected options: Docs
  2. if-else statement to apply condition on the count of selected options: Docs

{formmenu: default=choice1; choice2; choice3; name=choices; multiple=yes; formatter=items -> join(items, "BLAZE_AND")}
{if: count(choices)=1}Single option selected{else}Multiple options selected{endif}

Big thanks.

I apply your solution but i can't find for make special conditions on count fonction.

On my exemple, i have 3 choices but i wan't add more :

{formmenu: default=choice1; choice2; choice3; name=choices; multiple=yes; formatter=items -> join(items, "BLAZE_AND")}

{if: includes(choices, "choice1")}Text of choice 1{endif}
{if: count(choices)=1}{else}And{endif}
{if: includes(choices, "choice2")}Text of choice 2{endif}
{if: count(choices)=2}or and{else}{endif}
{if: includes(choices, "choice3")}Text of choice 3{endif}

Hey @Frenchy_Devs,
I'm not sure what the intended behavior here is, but here's one thing to consider.

  1. Create a named list of the texts and their dropdown values:
    {list=["choice a":"text of choice a", "choice b":"taxe of choice b",...]}
  2. Use the keys of the list as the values of the drop-down
    {formmenu: values={=keys(list)}; name=selected items; multiple=yes}
  3. Map the selection back to a list of the desired texts:
    {texts=map(selected items,(key)->list[key])}
  4. Then you can join the list of texts how ever you want. Two useful options are the "BLAZE_AND" and "BLAZE_OR":
    {=join(texts, "BLAZE_AND")}
    Or you can use repeat to iterate through the list and present it any way you want:
    {repeat: for (item,index) in texts}
    {=index}. {=item}
    {endrepeat}

I hope that this is useful. I'm happy to help you further if you need anything.

{list=["choice a":"text of choice a", "choice b":"taxe of choice b","choice c":"text of choice c"]}
{formmenu: values={=keys(list)}; name=selected items; multiple=yes}
{texts=map(`selected items`,(key)->list[key])}{=join(texts, "BLAZE_AND")}
{repeat: for (item,index) in texts}
{=index}. {=item}
{endrepeat}

1 Like

Big thanks for help :slight_smile:

"text of choice" is an exemple but in futur, it's complex and comprehensive content.

Between each text I need to have a "binding", for example, "and" "moreover" or "thus".

If I have only one choice selected, no "binding" text, if I select two or more, I need a binding between each.

Big thanks

result exemple :
text text text text text text text text text text text text text text text text text text text text .
text text text text . text text .
text text text text text text text text .
and
text text text text . text text .
text text text text text text text text .
and
text text text text . text text .

result exemple 2 :
text text text text . text text .
text text text text text text text text .
and
text text text text . text text .

Hi @Frenchy_Devs,

As @Dan_Barak1 suggested instead of using BLAZE_AND or BLAZE_OR, you can use your own specific binding. I have saved the binding in a variable and used that to join the chosen texts.

{note}{binding="\nand\n"}{list=["choice a":"text of choice a", "choice b":"text of choice b","choice c":"text of choice c"]}
{formmenu: values={=keys(list)}; name=selected items; multiple=yes}
{texts=map(`selected items`,(key)->list[key])}{endnote}{=join(texts, binding)}

Totaly that !

BUT ! With "list" fonction i'am very restricted with text in it.

I must use complexe zone text same like this :

{if: includes(choices, "choice1")}Text of choice 1{endif}

Big thanks

Hi @Frenchy_Devs,

I have made some changes in your snippet for your use case and you can try the following snippet.

{formmenu: choice1; choice2; default=choice3; name=choices; multiple=yes; formatter=items -> join(items, "BLAZE_AND")}

{if: includes(choices, "choice1")}Text of choice 1
And
{endif}{if: includes(choices, "choice2")}Text of choice 2
or and
{endif}{if: includes(choices, "choice3")}Text of choice 3{endif}

Ok. I see. But if i select only "choice 2" (for exemple), i have :

"Text of choice 2
or and"

without logic to have the "or and".

You can easily get rid of the extra binding as that can be there only for the last choice so you can use the toggle with default yes so that it will insert every time and disable the last toggle before inserting the form. I know this is not the best solution, but if I find a better solution, I will send it here.

{formmenu: choice1; choice2; default=choice3; name=choices; multiple=yes; formatter=items -> join(items, "BLAZE_AND")}

{if: includes(choices, "choice1")}Text of choice 1
{formtoggle: default=yes}And{endformtoggle}
{endif}{if: includes(choices, "choice2")}Text of choice 2
{formtoggle: default=yes}or and{endformtoggle}
{endif}{if: includes(choices, "choice3")}Text of choice 3{endif}