0

假设我想在多选屏幕(类型 = 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>
4

2 回答 2

1

在此静态场景中满足您的要求的一种简单方法是使用 isAnswerSelectedByClientKey 方法查看每个答案的“已检查状态”。此方法将返回,在我的方法中,我将所有“状态”写入一个数组,然后检查是否存在

            <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> 
于 2015-05-19T19:11:19.790 回答
0

您可以将条件定义为:

<condition>getQuestionValueNew() == ""</condition>

因此,当未选择任何内容时true,它将返回,如果选择了某些内容,则返回false

于 2015-05-19T12:14:39.847 回答