假设我想在多选屏幕(type = 4)中验证至少选中了一个复选框。如何在以下示例中定义相关验证的条件?
<question title="Preferrable Colors" type="4" key="#1">
<answer nextQuestionKey="END" key="#1_1" position="0">
<text>Pink</text>
</answer>
<answer nextQuestionKey="END" key="#1_2" position="1">
<text>Red</text>
</answer>
<answer nextQuestionKey="END" key="#1_3" position="2">
<text>Violet</text>
</answer>
<text>Select the colors you prefer </text>
<validation type="ERROR">
<condition>true</condition>
<text>Sorry, you have to select at least one color</text>
</validation>
</question>
答案 0 :(得分:1)
在此静态方案中满足您的要求的一种简单方法是使用isAnswerSelectedByClientKey方法查看每个答案的“已检查状态”。此方法将返回 true 或 false ,在我的方法中,我将所有“状态”写入数组并执行检查是否存在 true 之后。
<question title="Preferrable Colors" type="4" key="#1">
<answer nextQuestionKey="END" key="#1_1" position="0">
<text>Pink</text>
</answer>
<answer nextQuestionKey="END" key="#1_2" position="1">
<text>Red</text>
</answer>
<answer nextQuestionKey="END" key="#1_3" position="2">
<text>Violet</text>
</answer>
<text>Select the colors you prefer </text>
<validation type="ERROR">
<condition>hasValue(selArray, true) == false</condition>
<text>Sorry, you have to select at least one color</text>
</validation>
<onLeaveOkPrepareAssignment>
selArray = null;
selArray['1'] = isAnswerSelectedByClientKey($answer:'#1_1', null);
selArray['2'] = isAnswerSelectedByClientKey($answer:'#1_2', null);
selArray['3'] = isAnswerSelectedByClientKey($answer:'#1_3', null);
</onLeaveOkPrepareAssignment>
</question>
答案 1 :(得分:0)
您可以将条件定义为:
<condition>getQuestionValueNew() == ""</condition>
因此,如果未选择任何内容,则会返回true
,如果选择了某些内容,则会返回false
。