How to validate at least one of two optional fields in xlsx forms?

We’re trying to enforce a rule in a xlsx form where at least one of two optional fields must be filled out. Either field - or both - can be completed, but both can’t be left blank.

Context:

provide a separate field for erf number and street number respectively. Sometimes both are known, sometimes only one or the other.

The challenge is that neither field can be marked as required. And as expected, when a field is optional and left blank (""), its constraint doesn’t get evaluated, so the form allows submission even if both are empty.

Unfortunately, appearance=hidden and ``relevant=false` fields also prohibit constraints from firing, so our approach of adding a note field to act as an “error message” also didn’t work.

Having a visible, required, string field just to indicate an error just seem like terrible UX/UI and would confuse the CHW.

Has anyone dealt with this before or found a way to make this kind of conditional validation user-friendly in CHT?

Can you actually just use a required expression for both optional fields such that the field is only required if the other field is not populated?

type name label::en required
text opt_1 Option 1 ${opt_2} = ‘’
text opt_2 Option 2 ${opt_1} = ‘’

This should let you fill out both values, but will only require that one or the other is populated.

3 Likes

Great! @jkuester so required column does NOT only take yes / true() inputs.
I’ve confirmed this works, thank you!

3 Likes