SmartForms Conditional Fields

908
2
Jump to solution
10-12-2023 01:55 PM
KansasDASC
New Contributor III

Building out a form with multiple groups and multiple questions per group. Some questions are in the style of "Did you do your homework?" and the answer choices are "Yes, No". If someone entering the form selects the "No" option, I want a hidden field to appear where they can enter a reason. I don't need that field to appear when they hit "Yes".

I understand this to be conditional visibility, but that function in the SmartForms builder appears to have been removed. Googling a question like this brings up several posts, blogs, videos, etc from 2021 and shows different options than what's in there now.

So...how can this be achieved in SmartForms? I have tried the Arcade expressions, but it does not toggle the field on/off depending on the other questions' choice. What would be the preferred expression to make this happen?

1 Solution

Accepted Solutions
JustinReynolds
Occasional Contributor III

Hello,

It may be helpful if you paste the code you tried already in your original post as it may not be working for a simple correctable reason. I'm assuming that you are using ArcGIS Online.

Given that you have the two following fields:

  • hw_completed
  • hw_not_completed_reason

The visibility expression assigned to hw_not_completed_reason field looks like the following:

 

if (Lower($feature.hw_completed) != 'yes') { return true };
return false;


/*
Constraints (like visibility, requiredness, & editability) need to return either true or false (aka Boolean). 

This expression returns true (visible) if the users response is anything other than 'Yes' or 'yes', indicating that the homework was not completed. 

Otherwise, it returns false (not visible) because the homework was completed, so no reason is need.

*/

 

Here I created two text fields to support the example:

JustinReynolds_1-1697146814755.png

I clicked the gear icon next to visibility (found in the logic section after selecting the field "hw_not_completed_reason"). Then clicked add new expression. Then, near the bottom right corner I clicked the "Launch Arcade Editor" Option.  Then I gave my expression the name "vis_hw_not_completed_reason" based on the my field's name.  Then I wrote the expression and saved it.

JustinReynolds_0-1697146803731.png

 

 

 

 

 

- Justin Reynolds, PE

View solution in original post

2 Replies
JustinReynolds
Occasional Contributor III

Hello,

It may be helpful if you paste the code you tried already in your original post as it may not be working for a simple correctable reason. I'm assuming that you are using ArcGIS Online.

Given that you have the two following fields:

  • hw_completed
  • hw_not_completed_reason

The visibility expression assigned to hw_not_completed_reason field looks like the following:

 

if (Lower($feature.hw_completed) != 'yes') { return true };
return false;


/*
Constraints (like visibility, requiredness, & editability) need to return either true or false (aka Boolean). 

This expression returns true (visible) if the users response is anything other than 'Yes' or 'yes', indicating that the homework was not completed. 

Otherwise, it returns false (not visible) because the homework was completed, so no reason is need.

*/

 

Here I created two text fields to support the example:

JustinReynolds_1-1697146814755.png

I clicked the gear icon next to visibility (found in the logic section after selecting the field "hw_not_completed_reason"). Then clicked add new expression. Then, near the bottom right corner I clicked the "Launch Arcade Editor" Option.  Then I gave my expression the name "vis_hw_not_completed_reason" based on the my field's name.  Then I wrote the expression and saved it.

JustinReynolds_0-1697146803731.png

 

 

 

 

 

- Justin Reynolds, PE
KansasDASC
New Contributor III

Thanks, @JustinReynolds This was exactly what I was trying to do. I was using the Calculated Expression cog and not the Visible cog to get at the expression. Appreciate it!