Counting toggles

Hi again,

Is there a way to count input for toggles?

The snippet below will give an error message when AWC1 and another option is selected.

{note: trim=right}{formtoggle: name=AWC1; trim=yes}{endformtoggle}{formtoggle: name=AWC2; trim=yes}{endformtoggle}{formtoggle: name=AWC3; trim=yes}{endformtoggle}{formtoggle: name=Store Closed; trim=yes}{endformtoggle}{if: `AWC1` and (`AWC2` or `AWC3` or `Store Closed`)}
{error: You can only select one option. Please deselect either AWC1, AWC2, AWC3 or Store Closed.; block=yes}
{elseif: `AWC2` and `AWC3` and `Store Closed`}
{error: You can only select one option. Please deselect either AWC2, AWC3 or Store Closed.; block=yes}
{endif}{endnote}

However, if I select AWC2 and AWC3 then we don't.
I can duplicate this but there must be an easier way:

{note: trim=right}{formtoggle: name=AWC1; trim=yes}{endformtoggle}{formtoggle: name=AWC2; trim=yes}{endformtoggle}{formtoggle: name=AWC3; trim=yes}{endformtoggle}{formtoggle: name=Store Closed; trim=yes}{endformtoggle}
{if: `AWC1` and (`AWC2` or `AWC3` or `Store Closed`)}
{error: You can only select one option. Please deselect either AWC1, AWC2, AWC3 or Store Closed.; block=yes}
{elseif: `AWC2` and `AWC3` and `Store Closed`}
{error: You can only select one option. Please deselect either AWC2, AWC3 or Store Closed.; block=yes}
{endif}
{if: `AWC2` and (`AWC1` or `AWC3` or `Store Closed`)}
{error: You can only select one option. Please deselect either AWC1, AWC2, AWC3 or Store Closed.; block=yes}
{elseif: `AWC2` and `AWC3` and `Store Closed`}
{error: You can only select one option. Please deselect either AWC2, AWC3 or Store Closed.; block=yes}
{endif}{endnote}


I have tried using the AI but apparently the if command won't count inputs and says:
"Cannot convert "no" to a number."

Please help!

Hello Oliver,

You can achieve what you're looking for by creating a list with all your values, and then filtering for the selected ones. You can then count them and if you have more than a selected one, show the error. This will work regardless of how many toggles you have, just be sure to add new toggles to the list.

{note: trim=right}{formtoggle: name=AWC1; trim=yes}{endformtoggle}{formtoggle: name=AWC2; trim=yes}{endformtoggle}{formtoggle: name=AWC3; trim=yes}{endformtoggle}{formtoggle: name=store_closed; trim=yes}{endformtoggle}

{values=[awc1,awc2,awc3, store_closed]; trim=yes}
{numberOfSelectedToggles=count(filter(values, value -> value = yes)); trim=yes}

{if: numberofselectedtoggles > 1}
{error: You can only select one option. Please deselect either AWC1, AWC2, AWC3 or Store Closed.; block=yes}
{endif}{endnote}

Hi! Wouldn't it be easier to just use a single-select dropdown-menu for this?

{formmenu: default=Choice A; Choice B; Choice C}

1 Like

This looks to have done it, thank you!