Check if (at least) 2 out of 3 fields filled

1. What is the issue? Please be detailed.
I am designing a form with 3 text fields(fname, mname and sname) in the same group. I have added a calculate field check_names_count with the calculation
if((string-length(${fname})<0 and string-length(${mname})<0) or (string-length(${fname})<0 and string-length(${sname})<0) or (string-length(${mname})<0 and string-length(${sname})<0), "There must be at least 2 name items provided. First, Middle and Last names cannot all be empty.", "")
and a note names_count_note with relevant set to ${check_names_count}!="" and label set to ${check_names_count}.
The issue is, I am still able to fill in just the fname field and proceed just fine without the note field popping up with the desired error message to prompt the user/enumerator.

3. What have you tried to fix the issue?
I have tried setting the trigger of check_names_count to ${fname} or ${mname} or ${sname}

4. Upload any forms or screenshots you can share publicly below.

Ciao @aankrah,

Use below as the relevant for the note to warn user the names requirements.

if(string-length(${fname})>0,1,0) + if(string-length(${mname})>0,1,0) + if(string-length(${sname})>0,1,0) < 2

Change the note label to be contain instructions to enumerators, also remember to set the note as required to prevent user from proceeding until corrections are made.

You might also want to increase the string-length() to any expected shortest name (i.e.: a single space or character would still be evaluated as length 1…)

Jules R

1 Like

Worked like a charm!!
Thanks @jules_rugwiro

1 Like