If conditions in Constraint

Hello,

In my form I have a question on Transportation Type and a question on Departure Point.
Transportation is ‘car’, ‘bus’, ‘boat’, or ‘by foot’
Departure from Country A and B (ex India and Pakistan) can be by ‘car’, ‘bus’, ‘boat’, or ‘by foot’
Departure from Country C and D (ex Maldives and Seychelles) can only be by boat’

The below in the constraint doesn’t work:

if(${Transportation}=‘boat’, (${Departure_country}=‘MAL’ or ‘SEY’ '), (${Departure_country}=‘IND’ or ‘PAK’))

Any ideas?

Thanks!

Welcome to the community, @kt2630! Here are some examples of using the if-statements under the constraint:

Another one:

And this one too:

This too:

These workaround should help you understand the if-statement and solve your issue.

Thank you very much - this is very helpful!

1 Like

Hello @kt2630,
Did you check ypur form with the Online validator? (Always suggested, please.)
I think the problem is in your if logic and in your syntax. As far as I understand, it might need correction as:
if( ${Transportation}=‘boat’, (${Departure_country}=‘MAL’ or ${Departure_country}=‘SEY’ or
${Departure_country}=‘IND’ or
${Departure_country}=‘PAK’),
(${Departure_country}=‘MAL’ or ${Departure_country}=‘PAK’) ).

Or
if( ${Transportation}=‘boat’, true(), ${Departure_country}=‘IND’ or
${Departure_country}=‘PAK’ ).

Form design hint: More userfriendly solutions might be to

  • Use a choice_filter for the 2nd select_one, instead of a constraint. This would directly restrict a correct selection, instead of giving a post-entry constraint-error. (This might be easier if you start with the departure_country as 1st select.).
  • Use relevant to skip Transportation question for ‘SEY’ or ‘MAL’ as Departure_country
  • Set ‘boat’ (calculate) selected and read-only if ‘SEY’ or ‘MAL’ as Departure.

Side-note: What about airplane?

1 Like