Select to view content in your preferred language

Workaround: evaluate regex constraint before submission of form

352
3
08-01-2024 08:24 AM
Matt-Goodman
Frequent Contributor

A known deficiency with the current version of Survey123 Connect is that it does not evaluate constraints until form submission. Many users have the need or desire to have their surveys evaluate a regular expression constraint before proceeding to the next question or next page in their form (more on the problem here).

Below is a possible (although somewhat clunky) work-around. It uses 'note' type rows so that no new fields are required in the data schema. 

  1. Identify the data field row that you want to validate with regex and insert two new rows below it.
  2. Set both new row types to 'note'.
  3. For the first note, make its 'appearance' hidden and write an 'if' expression in the 'calculation' column that evaluates your regex expression, returning some simple Boolean-like values like OK/bad, True/False, Yes/No, etc. Example:  if(regex(${field2check}, '^[a-zA-Z]'), "OK", "bad")
  4. For the second note row, leave its 'appearance' visible, but set its 'relevant' column to ${field2check}!="" and ${calc_row}!="OK" (this means that this note will not be visible unless the field that you're trying to validate is not blank and it has been evaluated as not "OK" by the calculation done in the row above. Set the text ('label') for this row to whatever you want your error message to be. 

    Here is a simplified example:
    MattGoodman_0-1722525557075.png
    typenamelabelappearancerequiredrequired_messagecalculationconstraintconstraint_message::defaultconstraint_messagerelevant
    begin groupuser_infoUser Infofield-list       
    textnameName yesEnter a valid name to proceed     
    notenamechecknamecheckhidden  if(regex(${name}, '^[a-zA-Z]'), "OK", "")    
    notenameerrornoteEnter a valid name to proceed       ${name}!="" and ${namecheck}!="OK"
    rangeageAge yes     ${namecheck}="OK"
    textadditionalnotesAdditional Notes       ${age}!=""
    end group          

There may be more elegant workarounds, so if you're aware of ways to make this more slick, please comment. 

3 Replies
jcarlson
MVP Esteemed Contributor

I think it's a solid workaround, similar to what we do for immediate feedback on some of our forms.

Edit to add: if there's a better way to accomplish this, I'd love to know, too!

- Josh Carlson
Kendall County GIS
DougBrowning
MVP Esteemed Contributor

My method to use emoji's has been working out well.  It does not stop them though.

https://community.esri.com/t5/arcgis-survey123-documents/how-to-simulate-instant-data-checking-using... 

0 Kudos
abureaux
MVP Frequent Contributor

I'd make ${namecheck} a calculate. That way you can drop the "label" and "appearance". Less work is always a good thing.

Also, notes don't need "names", so you can delete "nameerrornote" from the name column entirely.

Otherwise ya, doing it line by line is the only way.

As @DougBrowning mentioned, emojis work well for visual feedback (would be amazing if that was a built-in behaviour). But in the end, do whatever works well for you.

0 Kudos