Custom output based on dropdown selection

I'm wondering if I can assign certain values to each dropdown selection without having to create a conditional statement for each option?

{formmenu: A;B;C; name=options}
{if: options="A"}{output="hello"}{elseif: options="B"}{output="hi"}{elseif:options="C"}{output="hey"}{endif}
{=output}

Ideally, I'd like to avoid the {IF} statements and be still able to display the desired outputs.

Great question! You can use a keyed list to avoid that:

{formmenu: A; B; C; name=options}
{mapping=["A": "hello", "B": "hi", "C": "hey"]}
{output=mapping[options]}
{=output}

1 Like

Quick as always Gaurang. Thank you so much!

1 Like

Hey Gaurang, I tried to use this method when importing snippets and it didn't work. Is there a workaround?

Can you please share your two snippets - the one that has this menu and the one you were importing?

{note}{formmenu: default=Option 1; Option 2; Option 3; name=choices}{endnote}
{mapping=["Option 1":{import:/snippet1},"Option 2":{import:/snippet2},"Option 3":{import:/snippet3}]}
{output=mapping[choices]}
{=output}

Invoice Number: {formtext: name=invNum}
Product Code: {formtext: name=itemNum}
Freight Handling Code: {formtext: name=FH Code}
Total Credit: {formtext: name=credAmount}
Quantity Received Damaged: {formtext: name=Qty Damaged}
Lot Number Damaged: {formtext: name=Lot # Damaged}
Signed POD Available: {formtext: name=Y/N (Attach to email)}
Pictures of Damages Available: {formtext: name=Y/N}
Additional Comments: {formparagraph}

I see your requirement now. You are trying to do dynamic imports - where a specific snippet is imported based on a particular condition. This is currently not possible to do, although it is a pending feature request.

I request you to upvote it and add your use case there as well.

1 Like