如何验证在多 Select 屏幕中至少选中了一个复选框
How to validate that at least one check box is selected in a Multi Select Screen
假设我想在多 Select 屏幕(类型 = 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>
您可以将条件定义为:
<condition>getQuestionValueNew() == ""</condition>
因此,当没有选择任何东西时,这个 returns true
如果选择了东西,它 returns false
.
在此静态场景中满足您的要求的一种简单方法是使用 isAnswerSelectedByClientKey 方法查看每个答案的 'checked state'。此方法将 return true 或 false 在我的方法中,我将所有 'states' 写入数组并执行之后检查 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>
假设我想在多 Select 屏幕(类型 = 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>
您可以将条件定义为:
<condition>getQuestionValueNew() == ""</condition>
因此,当没有选择任何东西时,这个 returns true
如果选择了东西,它 returns false
.
在此静态场景中满足您的要求的一种简单方法是使用 isAnswerSelectedByClientKey 方法查看每个答案的 'checked state'。此方法将 return true 或 false 在我的方法中,我将所有 'states' 写入数组并执行之后检查 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>