Select to view content in your preferred language

Validate Date Ranges in FieldMaps Smart Forms

285
2
Jump to solution
a month ago
Caitlin_Todd_LCOR
New Contributor III

Hello, 

I'm hoping there's an Arcade function that I've overlooked for this issue. 

I have a smart form that needs to track when a person arrives and when a person leaves an inspection site. So ideally I'd like to put the following validation rules in the smart form.

  1. Arrival date cannot be in the future.
  2. "left site" date cannot be before the arrival date. 

But all I'm seeing are options to write Arcade expressions for: required, editable, or calculated. Not seeing Validation anywhere. 

Due to other user requirements I need this in AGOL and not in Enterprise, so I'm unable to leverage attribute rules. 

(unless ESRI is now allowing for custom attribute rules in AGOL hosted feature layers?)

Many thanks for any thoughts & ideas!

Caitlin

Lane County GIS

0 Kudos
1 Solution

Accepted Solutions
JustinReynolds
Regular Contributor

Hi Caitlin,

Form validation and validation expressions are not supported yet.  I suspect that this will be supported in one form or another in the future.

Although form validation is not explicitly supported, there are a few strategies that can be deployed to mimic the intent of form validation. What is needed is a way to prevent form submission if at least one field contains data that doesn't meet some criteria.

One that our team uses involves adding a new field whose sole purpose is to indicate whether or not the form has fields that are invalid, based on whatever criteria we need.  This is a required field that calculates to 'null' if any field is invalid, otherwise it calculates to something that is NOT 'null'.  If the form is valid, the value of this field doesn't matter, it just can't be null because having a value allows form submission, while having no value will prevent form submission.  

This trick works well when combining it with the new 'info' elements. It works like this:

A user enters data into field x that we consider to be invalid for one reason or another.  The required validation field calculates to null, indicating the form is now invalid and thus will actively prevent the user from submitting their form (if they try it will say 1 attribute failed).  Now, this works, but isn't really enough, as the user at this point has no idea what is wrong.  This is where the new info elements come into play.  For each condition we have in the validation field's calculation we add an info element whose visibility expression is also tied to that condition.  So if field x's value should contain a period at position 9 and be followed by at least 4 numbers, but isn't the info element would be visible, the validation field would be null, and the user would not be able to submit the form.  As soon as field x met that condition, the info element would disappear, the validation field would have a value ('Form is Valid' or similar), and the user would be able to submit the form.

For you scenario, it might look like the following.  Here we have 3 info elements at the top of the form, each is conditionally visible.  We have your two date fields, that are required and the form validation field that is required and calculated, returning null if invalid to prevent form submission and returning 'Form is Valid' to allow form submission.

JustinReynolds_0-1717110210310.png

Expression Details Below:

The example above has 3 Visibility Expressions (1 for each Info Element) and 1 Value Expression (for the form validation field).

JustinReynolds_1-1717110955874.png

JustinReynolds_2-1717111040115.png


The following return true (is visible) if the field is not valid otherwise returns false (not visible).

JustinReynolds_3-1717111083972.png

JustinReynolds_5-1717111140673.png

The following returns false (not visible) if form validation field is null (any condition not valid) otherwise returns true (visible).

JustinReynolds_6-1717111232487.png

The following value expressions returns null if a some condition indicates not valid, otherwise return a string 'Form is Valid' indicating none of the invalid scenarios were met.

JustinReynolds_7-1717111402867.png

 

And Field Maps result looks like the following:

JustinReynolds_9-1717111636991.jpegJustinReynolds_10-1717111649750.jpeg

JustinReynolds_12-1717111685814.jpegJustinReynolds_13-1717111699961.jpeg

Hope this helps!

 

- Justin Reynolds, PE

View solution in original post

2 Replies
JustinReynolds
Regular Contributor

Hi Caitlin,

Form validation and validation expressions are not supported yet.  I suspect that this will be supported in one form or another in the future.

Although form validation is not explicitly supported, there are a few strategies that can be deployed to mimic the intent of form validation. What is needed is a way to prevent form submission if at least one field contains data that doesn't meet some criteria.

One that our team uses involves adding a new field whose sole purpose is to indicate whether or not the form has fields that are invalid, based on whatever criteria we need.  This is a required field that calculates to 'null' if any field is invalid, otherwise it calculates to something that is NOT 'null'.  If the form is valid, the value of this field doesn't matter, it just can't be null because having a value allows form submission, while having no value will prevent form submission.  

This trick works well when combining it with the new 'info' elements. It works like this:

A user enters data into field x that we consider to be invalid for one reason or another.  The required validation field calculates to null, indicating the form is now invalid and thus will actively prevent the user from submitting their form (if they try it will say 1 attribute failed).  Now, this works, but isn't really enough, as the user at this point has no idea what is wrong.  This is where the new info elements come into play.  For each condition we have in the validation field's calculation we add an info element whose visibility expression is also tied to that condition.  So if field x's value should contain a period at position 9 and be followed by at least 4 numbers, but isn't the info element would be visible, the validation field would be null, and the user would not be able to submit the form.  As soon as field x met that condition, the info element would disappear, the validation field would have a value ('Form is Valid' or similar), and the user would be able to submit the form.

For you scenario, it might look like the following.  Here we have 3 info elements at the top of the form, each is conditionally visible.  We have your two date fields, that are required and the form validation field that is required and calculated, returning null if invalid to prevent form submission and returning 'Form is Valid' to allow form submission.

JustinReynolds_0-1717110210310.png

Expression Details Below:

The example above has 3 Visibility Expressions (1 for each Info Element) and 1 Value Expression (for the form validation field).

JustinReynolds_1-1717110955874.png

JustinReynolds_2-1717111040115.png


The following return true (is visible) if the field is not valid otherwise returns false (not visible).

JustinReynolds_3-1717111083972.png

JustinReynolds_5-1717111140673.png

The following returns false (not visible) if form validation field is null (any condition not valid) otherwise returns true (visible).

JustinReynolds_6-1717111232487.png

The following value expressions returns null if a some condition indicates not valid, otherwise return a string 'Form is Valid' indicating none of the invalid scenarios were met.

JustinReynolds_7-1717111402867.png

 

And Field Maps result looks like the following:

JustinReynolds_9-1717111636991.jpegJustinReynolds_10-1717111649750.jpeg

JustinReynolds_12-1717111685814.jpegJustinReynolds_13-1717111699961.jpeg

Hope this helps!

 

- Justin Reynolds, PE
Caitlin_Todd_LCOR
New Contributor III

Thanks @JustinReynolds ! That works wonderfully! Its a shame that validation isn't supported yet, but hopefully it will be soon. 

It took me a minute to realize the info elements you mentioned are only available in FieldMaps Designer and not in the form editor in the map viewer. But once there it was easy to set everything up like you described and it works great in our mobile maps. 

Have a great day!

-Caitlin