I have 2 fields one called email and the other phone. I want to make it so that either one of them have to be filled in for the survey to be sent. How do I set the required and constraint fields? Any help is appreciated
Solved! Go to Solution.
For these it always ends up in a dependency cycle. So I use a 3rd field like this.
| type | name | label | hint | constraint | constraint_message | required | required_message | appearance | default | readonly | relevant | calculation |
| text | fieldA | fieldA | ||||||||||
| text | fieldB | fieldB | ||||||||||
| calculate | checkfields | checkfields | .!='' | Must fill out fieldA or B | coalesce(${fieldA}, ${fieldB}) |
Someone may have another idea. Hope it helps.
For these it always ends up in a dependency cycle. So I use a 3rd field like this.
| type | name | label | hint | constraint | constraint_message | required | required_message | appearance | default | readonly | relevant | calculation |
| text | fieldA | fieldA | ||||||||||
| text | fieldB | fieldB | ||||||||||
| calculate | checkfields | checkfields | .!='' | Must fill out fieldA or B | coalesce(${fieldA}, ${fieldB}) |
Someone may have another idea. Hope it helps.
Doug Brwoing with the WIN! Thank you that solved it!
How did you solve this. Which one is set to required?
Neither is set to required. You instead set the constraint on field 3 to !=''. This will fire if both are blank but not if either one has a value.
Has anyone tried this solution recently? I had built a survey in Survey123 Connect a few months back implementing this solution, but it does not appear to work anymore. I tried setting up similar constraints on multiple fields, but they survey goes through without any issues.
I like Doug's solution, but we solved this by creating a select one question (${contact}) that asks the user "how do you wish to be contacted" with (text message, email, phone) as options. Then you make the email and phone questions (both set to required) visible/hidden with a relevant expression. selected(${contact},'email') on the email question or selected(${contact},'phone') or selected(${contact},'text_message'). if the question is relevant, it will be required.
Here we are years later and you are correct. Doug's solution throws the constraint in the Survey123 Connect app, but no constraint is thrown when I complete the published survey in my browser.
@cquick2 For a browser I would try adding a space . = "" and also the actual field name ${field3} != "". If no then next try string-length > 0 to check. I have seen issues in the browser with all of these.
Maybe even try moving the coalesce calc to its own field then add a constraint on that field to field 3. It could be that it is checking in the wrong order.
Hi Doug,
This fix seems to be appropriate for something I'm trying to do as well - however I have FIVE fields where I want at least one with a value. I tried to use your fix but the five fields in the coalesce function but Collect kicked off that I have five fields instead of two... Any thoughts on a fix? I thought I could use coalesce for more than two fields....
Cheers! Laura