xpages checkbox single value selection

时光怂恿深爱的人放手 提交于 2019-12-11 02:45:01

问题


Is it possible the users to select only one value from a <xp:checkBoxGroup>? In other words, the checkBoxGroup to work like a radioButton?

I know I could easily change the control to a radioButton but I was just curios.


回答1:


You can use the following code to use a checkboxgroup with a single selection. The code is not perfect, because you need two clicks to activate a new checkbox.

<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>


来源:https://stackoverflow.com/questions/26352924/xpages-checkbox-single-value-selection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!