用户是否可以从 <xp:checkBoxGroup>
中仅选择一个值?换句话说,checkBoxGroup 可以像 radioButton 一样工作吗?
我知道我可以轻松地将控件更改为 radioButton,但我只是好奇。
最佳答案
您可以使用以下代码将复选框组与单个选择结合使用。该代码并不完美,因为您需要单击两次才能激活新的复选框。
<xp:checkBoxGroup id="checkBoxGroup1">
<xp:selectItem itemLabel="first" itemValue="1"></xp:selectItem>
<xp:selectItem itemLabel="second" itemValue="2"></xp:selectItem>
<xp:selectItem itemLabel="third" itemValue="3"></xp:selectItem>
<xp:selectItem itemLabel="fourth" itemValue="4"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="checkBoxGroup1">
<xp:this.action>
<![CDATA[#{javascript:var checkedValues = getComponent("checkBoxGroup1").getAttributes().get("value")
varArray = new Array(0)
varArray[0] = checkedValues.length < 2 ? checkedValues[0] : undefined
getComponent("checkBoxGroup1").getAttributes().put("value", varArray);
}]]>
</xp:this.action></xp:eventHandler></xp:checkBoxGroup>
关于xpages 复选框单值选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26352924/