Select to view content in your preferred language

How to set minimum characters constraints in survey123 connect?

12426
6
Jump to solution
01-11-2017 04:42 AM
AdministratorAGOL_ODIMM
New Contributor III

#Survey123 #minimumcharacters

Tags (1)
1 Solution

Accepted Solutions
IsmaelChivite
Esri Notable Contributor

Hi! Both approaches above are valid.

TypeNameLabelConstraintbody::esri:inputMask
textAssetIDAsset IDstring-length(.)>4
textAssetNameAsset NameAAAAaaa

Here are the pros and cons I see in each:

  • Using string-length in a constraint: The syntax is as shown above, but you could also use something like string-length(${AssetID})>4.The period (.) is a shortcut to the value of the question in which the expression evaluates. I like using this approach because it allows you to ensure  that the input from the user has at least the minimum number of characters you specify. In the example above four (4). With a constraint like this you could have as many characters as your field allows. By default text questions allow a maximum  number of 255 characters.  For text type of questions, the expression in your constraint will be evaluated when the user jumps to the next question, and when the user tries to submit the survey. I also like the technique of using constraints because you can customize the warning the end user will get when the expression is violated by using the constraint_message column in the XLSForm.
  • Using inputMasks: This was a great suggestion by Brent. A mask like the one in the example above will allow a string with at least 4 characters and optionally up to 3 more characters. I like two things about input masks: first, that the end user gets feedback about the validity of the input as the values are  entered. The input will be shown in red until it is valid. For example, while you type the first 3 characters the input will be shown in red, but when you reach 4 characters it will turn black indicating that the input is correct.  Input masks also have the advantage that let you control the type of text that is accepted according to this table.  You can for example make the values by all alphanumeric, or just alphabetic , a combination of both etc. 

View solution in original post

6 Replies
JoeFlannery
Regular Contributor II

Igor:

Near the bottom of this page:

Open Data Kit » Binding 

You will find this example >> "Constraints: Answer must between 4 and 10 characters long (inclusive)"

This should answer your question.

Joe

AdministratorAGOL_ODIMM
New Contributor III

Joe thanks a lot for your reply, but it seems that expression 

"string-length(.) >= 4 and string-length(.) <= 10"

is not working in Survey123 Connect . I'm beginner in editing of XML forms so maybe I missed something?

0 Kudos
JoeFlannery
Regular Contributor II

Igor:

I am a beginner, too, so I am sorry that I cannot provide further guidance to the use of that constraint code.  It seems like you might be heading in the right direction with this code, but now it is a matter of trial and error and maybe some good internet searching to find the final answer.

Isn't this fun?  Really - it's fun to be challenged and learn new things.

Good Luck and post back to this thread if you find something that works for you.  Others will be interested.

BrentKinal1
Occasional Contributor III

Igor, 

Joe was kind of correct on how to go about it, you do need to use binding however Survey123 goes about it a different way than ODK. You will want to use an input mask.

To do this in Survey123 Connect fill in the  the body::esri:SurveyMask column (this is the last column in the survey form column x) for your field with the following.

XXXXxxxxxx the capital 'X' makes the character required lower case 'x' is optional to the maximum number of total digits in your mask (in your case 10).

X,x will allow any ascii character

if you just want alphabetic characters use A, a (e.g. AAAAaaaaaa)

numeric characters (0- 9) required = 9, optional = 0 (e.g. 9999000000)

the whole list of options and more about input masks can be found here near the bottom of the page:

Esri custom columns—Survey123 for ArcGIS | ArcGIS 

Hope this helps!

Brent

IsmaelChivite
Esri Notable Contributor

Hi! Both approaches above are valid.

TypeNameLabelConstraintbody::esri:inputMask
textAssetIDAsset IDstring-length(.)>4
textAssetNameAsset NameAAAAaaa

Here are the pros and cons I see in each:

  • Using string-length in a constraint: The syntax is as shown above, but you could also use something like string-length(${AssetID})>4.The period (.) is a shortcut to the value of the question in which the expression evaluates. I like using this approach because it allows you to ensure  that the input from the user has at least the minimum number of characters you specify. In the example above four (4). With a constraint like this you could have as many characters as your field allows. By default text questions allow a maximum  number of 255 characters.  For text type of questions, the expression in your constraint will be evaluated when the user jumps to the next question, and when the user tries to submit the survey. I also like the technique of using constraints because you can customize the warning the end user will get when the expression is violated by using the constraint_message column in the XLSForm.
  • Using inputMasks: This was a great suggestion by Brent. A mask like the one in the example above will allow a string with at least 4 characters and optionally up to 3 more characters. I like two things about input masks: first, that the end user gets feedback about the validity of the input as the values are  entered. The input will be shown in red until it is valid. For example, while you type the first 3 characters the input will be shown in red, but when you reach 4 characters it will turn black indicating that the input is correct.  Input masks also have the advantage that let you control the type of text that is accepted according to this table.  You can for example make the values by all alphanumeric, or just alphabetic , a combination of both etc. 
AndrewHargreaves2
Occasional Contributor III

Hi Ismael Chivite

If I follow what you say above then the above constraint should work when {MATERIALS_USED} = YES and QUANTITY1 has no value. However, using a spinner on an integer results in an initial value of 'null' meaning the constraint never fires.

I've highlighted this in a similar thread here.

0 Kudos