Florin M.
Florin M.

Reputation: 2169

xpages checkbox single value selection

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.

Upvotes: 2

Views: 554

Answers (1)

PoisonedYouth
PoisonedYouth

Reputation: 546

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>

Upvotes: 3

Related Questions