Field Maps web form - make field visible in all cases but required for only certain previous field domain values

476
1
06-21-2022 12:05 PM
Caryn_Jane
New Contributor

In the Field Maps configurable web form I am trying to make a Notes field visible in all cases but required for only certain previous field domain values.

Use case: For tree monitoring we want staff to be able to make notes on all tree conditions, but if the tree is dead I want to require notes are made.

Currently, I can add conditional visibility but can not parse our which field values make this field

Tags (2)
0 Kudos
1 Reply
JustinReynolds
Occasional Contributor III

This is possible with the constraint arcade profile (the same one used for conditional visibility), but there is a trick to it right now, since you can't "technically" author it in the Field Map Web App's UI ATM.

That is to say...Field Maps Mobile supports conditionally required fields, but the web app for authoring them doesn't.

Most fields in my forms are required by default, but if a user changes a status field to "Draft" or "Void"  then I set the requiredExpression to False on all or some fields to allow them to submit as a draft....  this is a work around for not having a true "save as draft" feature in Field Maps.  This can be extended to any criteria you wish.

So how is this done?


Author a visibility expression in the UI that you will use instead for a required expression.  Just create it, but don't assign it in the Field Maps UI for now.  Once that is complete, open the web map in AGO Assistant to edit the JSON and add that expression name to the required expression. 

Below is an example.

JustinReynolds_0-1655839278153.png

A required expression written as a visibility expression (left unassigned) in the field maps web app. The important part is that it should return either True or False.

 

// constraint_req_cond_all_subs_x_draft_x_no_station_x_offset_dir_is_c
// field is required for all submission conditions except 
// drafts or if the hasStationing field is false... aka 0
// or if the offset direction is set to center

// expression description
console('Evaluate Constraint: Required Field, except drafts or if has stationing is false or if offset direction is center.')

// Prod Values
var status = $feature["feature_status"];
var hasStationing = $feature["has_stationing"];
var offsetDirection = $feature["stationing_offset_direction"];

// Test Values
// var status = 'Pass'
// var status = 'Draft'
// var offsetDirection = 'R'
// var offsetDirection = 'C'
// var hasStationing = 0
// var hasStationing = 1

console('>>> Status: ' + status);
console('>>> Offset Direction: ' + offsetDirection);
console('>>> Has Stationing: ' + hasStationing);

// execute the expression
if (status == 'Draft' || hasStationing == 0 || offsetDirection == 'C') {
    console('>>> Is required: False')
    return false; // if status is draft required is false
} else {
    console('>>> Is required: True')
    return true; // else required is true
};

 

And the JSON form element manipulated using ago assistant.

 

...
{
  "description": "Enter the offset distance",
  "label": "Station Offset Distance",
  "type": "field",
  "visibilityExpression": "constraint_vis_cond_offset_direction_is_l_or_r",
  "editable": true,
  "fieldName": "stationing_offset_distance",
  "hint": "e.g. 56.2",
  "inputType": {
                  type": "text-box",
                  "minLength": 0
               },
  "requiredExpression": 
       "constraint_req_cond_all_subs_x_draft_station_offset_dir"
}
...

 

Note that this works for editability as well.

I have a habit of naming my expressions as follows to keep track of what the intended purpose is.
constraint_req_cond_   Expression for conditional required fields
constraint_edt_cond_   Expression for conditional field editability
constraint_vis_cond_    Expression for conditional field/group visibility


I imagine that there will be native support for authoring conditional required and editable fields fairly soon.  For now it is a bit hacky.

- Justin Reynolds, PE