Regarding Ishmael's post on Multiple Choice questions, I see the ability to review individual items within a select_multiple type; is it possible to review if a list of items are selected?
I have a client who is observing activities, and which observed activities are unsafe, both fields reference the same choice list. I'd like to add a constraint that ensures that if a item is selected in the 'unsafe' field it is also selected in the 'observed' field. Can something along these lines be done?
type | name | label | constraint | constraint_message |
select_multiple Activities | observed | Observed Activities | ||
select_multiple Activities | unsafe | Unsafe Activities | selected(${observed}, ${unsafe} ) | Unsafe Activities must also be noted as Observed above |
Hi Paul,
I think that this is possible, but a bit more complicated. The basic unit of the constraint check is
For a given value, is it selected in observed? If so, is it selected in unsafe?
This translates to the following in XLSForm formulas:
if(selected(${observed}, 'a'), selected(${unsafe},'a'), true)
if( observed has the value a selected, then determine if unsafe selects value a, otherwise the constraint is met)
You would repeat this for each value in the list, joining the parts to gather with 'and' so that if one is not met, the entire thing false:
if(selected(${observed}, 'a'), selected(${unsafe},'a'), true) and if(selected(${observed}, 'b'), selected(${unsafe},'b'), true) and ...
Note this is to ensure that if it has been selected in observed, that it appears in unsafe- this would let unsafe have additional values that are not selected in observed.
Hi James Tedrick
I'm following the above logic, but getting nothing. Here's my constraint statement in my [COVER_LEVEL] row:
if(selected(${COVERED_OVER}, 'NO'), selected(${COVER_LEVEL},'UNKNOWN'), true)
If I set {COVERED_OVER}= 'NO' and ${COVER_LEVEL}= 'UNKNOWN' my message fails to appear. Any advice is gratefully received.
Thanks
Hi Andrew,
This is on a constraint, correct? The formula you have translates to:
If covered_over is no, cover_level must be UNKNOWN; if covered_over is not no, any value is valid
If you you want unknown to not be a valid answer when covered_over is no, you would want:
if(selected(${covered_over}, 'no'), not(selected(${cover_level}, 'unknown')), true)
One more for you James Tedrick
Can the logic you describe above for the orginal questions contain an 'or'? Sadly, it appears not as I'm trying the below with no success:
if(selected(${COVERED_OVER}, 'NO'), not(selected(${COVER_LEVEL}, 'UNKNOWN')), true) or if(selected(${COVERED_OVER}, 'UNKNOWN'), not(selected(${COVER_LEVEL}, 'BELOW_GRADE')), true)
The first part, before the 'or', works fine upon validation however the second half of the statement is failing to do anything.
Joining two constraints together, you probably want to use 'and' instead of or. and will require both statements to be true for the answer to be valid, or will require one of the statements to be true:
Statement (expression1 __ expression2) | Result |
---|---|
true and true | true |
true and false | false |
false and true | false |
false and false | false |
true or true | true |
true or false | true |
false or true | true |
false or false | false |
James Tedrick that's just my point; If either statement is TRUE then the constraint is also TRUE. For example:
if(selected(${COVERED_OVER}, 'NO'), not(selected(${COVER_LEVEL}, 'UNKNOWN')), true) or if(selected(${COVERED_OVER}, 'UNKNOWN'), not(selected(${COVER_LEVEL}, 'BELOW_GRADE')), true)
should result in a constrain triggering:
if COVERED_OVER is NO, COVER_LEVEL must NOT be UNKNOWN
or
if COVERED_OVER is UNKNOWN, COVER_LEVEL must NOT be BELOW_GRADE
However, as described only the statement before the 'or' works to trigger the constraint....
Hi Andrew,
You're actually wanting the reverse - constraints fire when a statement evaluates as FALSE (that's why there's not() in the function I created - to flip it to a "can't be <value>"). You do want to use 'and' (all the requirements must be met) instead of 'or' (one of the requirements must be met).
OR is a little confusing because it strays a bit from conversational English:
Q: Do you want to go out for dinner or cook at home?
A: Yes
Thank you James Tedrick
#SyntaxKing!