【问题标题】:xpages checkbox single value selectionxpages 复选框单值选择
【发布时间】:2014-12-08 18:45:20
【问题描述】:

用户是否可以从<xp:checkBoxGroup> 中仅选择一个值?换句话说,checkBoxGroup 能像radioButton 一样工作吗?

我知道我可以轻松地将控件更改为单选按钮,但我只是好奇。

【问题讨论】:

标签: xpages


【解决方案1】:

您可以使用以下代码将复选框组与单个选择一起使用。该代码并不完美,因为您需要单击两次才能激活一个新复选框。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    相关资源
    最近更新 更多