CMS Development

bholsey
Member

Using "choice" field as a display condition to determine if "form" field shows up

Hello,

I am trying to create a module where I have a choice field (layout) with 4 choices: 

  • 1 column
  • 2 column
  • 3 columm
  • Form (full width)

I have set up a form field where the display condition is set to the following:

Screen Shot 2022-05-27 at 11.49.58 AM.png

However, when I go to select the "form" layout in my module the form field does not show up. my fields.json file looks like the following:

Screen Shot 2022-05-27 at 11.53.56 AM.png

Basically, I am not sure what value to enter in the display conditions "value" field when it is dependent on a choice field instead of a boolean.

Thanks in advance for any help here!

0 Upvotes
1 Reply 1
Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Using "choice" field as a display condition to determine if "form" field shows up

Hi @bholsey

 

write your conditional logic not as JSON but as value. 

 

Your options should look something like this:

Anton_0-1653681829331.png

 

and the conditional logic should be 

Anton_1-1653681886010.png

 

The if-statement in the HTML should look like this:

{% if module.layout == "col-md-12" %}
{# content for 1 Column goes here #}

{% elif module.layout == "col-md-6" %}
{# content for 2 Column goes here #}

{% elif module.layout == "col-md-4" %}
{# content for 3 Column goes here #}

{% elif module.layout == "col-md-12 box-form" %} {# instead of elif... you can write just else #}
{# content for form goes here #}

{% endif %}

 

 

hope this helps.

 

 

best, 

Anton

Anton Bujanowski Signature
0 Upvotes