Conditionally include elements in a formmenu?

Hi there! Is there any way to conditionally include elements in a formmenu? Or do I need a separate formmenu for each condition?

The "if" conditions would be based on the value of variables pulled from Data Blaze, not form data.
I think maybe this could be doable if the form menu choices could be pulled from a list, and the list could be populated conditionally?

Hi Megan,

The formmenu command has a values settings that can take a list to specify the options.

Here's an example:

{options=["Excellent", "Good", "Average", "Poor", "Awful"]}

Selection: {formmenu: values={=options}}

You could pull that list from Data Blaze if you wanted and also manipulate the elements in it based on your conditions. Let us know if you need help with it.

I created a snippet for you to use, but it seems bugged in the preview. Try to copy it to your dashboard and remove the "" from the "else variables", i.e {=choice1[""]} should be {=choice1}

{formmenu: name=Formmenu; values={=listvalues}}{formtoggle: name=check; default=no}
{listvalues=merge(listvaluezero, choice1, choice2, choice3)}
{if: formmenu = "choice 1"} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Convallis. Aptent. Primis. {elseif: formmenu = "choice 2"} Mus. Pharetra. Fusce. Bibendum. Sapien. Magna. Ac. Convallis. Ullamcorper. Leo. Ultrices. Elit. Donec. Iaculis. Ultrices. Erat. Phasellus.{elseif: formmenu = "choice 3"}Porta quam auctor. Sociis ultricies ullamcorper. Montes euismod auctor. {endif}

{note: trim=yes}{if: 1 + 1 = 2} {choice1=["choice 1"]}{else}{choice1=[""]}{endif}
{if: check} {choice2=["choice 2"]}{else}{choice2=[""]}{endif}
{if: formmenu = "choice 2"} {choice3=["choice 3"]}{else}{choice3=[""]}{endif}
{listvaluezero=[""]} {endnote: trim=yes}

1 Like

The title of the Text Blaze chapter in my imaginary autobiography is definitely "How a simple text expander app taught me to code."
Thanks, both of you! I think I have this working mostly the way I want it to. Two questions:

  1. Is there a way to set a default value to whatever ends up being first in the list?
  2. If I select a row from Data Blaze, then change my mind and remove it, the Formmenu still contains values based on the conditions of that row. Any way to avoid?

You're welcome! :smile:

The value that ends up being the first is the first one from the list, i.e
{listvalues=merge(choice3, choice1, choice2, listvaluezero)} will make "choice 3" appear first.

The formmenu should "remove" the value if you select / have selected something else in the formmenu. That's why I like to include the zero-value ( {listvaluezero=[""]} ) as a first option.

1 Like