I have an integer field called num1. Has a default of zero. But you can erase that zero and leave the field blank. This blank field is not considered an integer (kills calculations for instance).
I want to put a constraint on it so you don't leave it empty (i.e. no number, no text). I can't seem to do it.
I have tried testing to see what this "empty" integer field is interpreted as, and I can tell you this:
${num1}='' is FALSE
${num1}=NaN is FALSE
number(${num1}) is BLANK
string-length(${num1}) is 0
string-length(number(${num1})) is 0
string-length(string(${num1})) is 0
here is the survey with the num1 field empty:
and here with the num1 field with a valid number:
I tried using any of these in a constraint (e.g. string-length(.)>0 ) but that is ignored, or not seen as an issue as it happily lets me submit with this blank integer field.
Is there a way to constrain it?
I have worked around it by using a calculation in another field, but was hoping I would not need to do this.
survey123 xlsx attached.
Thanks,
Tom S.
P.S. ${num1}=null is FALSE, ${num1}=undefined is FALSE as well.
Does required work?
I had an issue for a bit that you had to use string-length != or = 0. >0 never worked - not sure why but could be that it is considered text.
Hope that helps.
Thanks Doug for the reply. Yes, required will do it, but I don't want to make it required if I don't have to. Maybe there is no difference between required and constraint of a number/digit, have to ponder that.
My workaround was to make that field a null field and add another field that was calc'ed via an if statement, which honors the string-length query (if(string-length(${num1})=0,0,${num1})
Tom
Hi Tom,
In Survey123 terms, a required field is a field that must not be blank - you should make the field required.
Another approach would be to wrap the the question in coalesce(${q}, 0) to provide a default value when blank.
Hello, I know this thread is older but I stumbled on it when I was troubleshooting something in a survey and wanted to post a link to some useful esri documentation on empty values.
Particularly relevant to this particular post:
Empty values for integer and decimal questions are represented as NaN (not a number). This is a special value that represents the absence of a valid value.
Hope this maybe helps someone!