1

I have a repeat control and populating a checkboxgroup with items from a viewScope array. Sample code is :

<xp:repeat id="repeat4" rows="100" value="#{viewScope.choices}"
    indexVar="rownumber" var="row" first="0">

    <xp:checkBoxGroup id="checkBoxGroup2" layout="lineDirection">
        <xp:selectItems>
            <xp:this.value><![CDATA[#{javascript:if (viewScope.choices[rownumber].get(1)==viewScope.line){
            return viewScope.choices[rownumber].get(0)
           }}]]></xp:this.value>
        </xp:selectItems>
    </xp:checkBoxGroup>
    <xe:tooltip id="tooltip1" for="checkBoxGroup2">
        <xe:this.label><![CDATA[#{javascript:return viewScope.choices[rownumber].get(1)}]]></xe:this.label>
    </xe:tooltip>
</xp:repeat>

I'm reading the checked values with : @Text(getComponent("checkBoxGroup2").getSubmittedValue());

The problem is that it seems I can only read the last selected/ deselected value this way.

I guess it has something to do with the selecteditems that isn't returning an array, but how can I return an array with the given data ?

Marc Jonkers
  • 496
  • 1
  • 7
  • 17

1 Answers1

0

You can't use checkBoxGroup in this case. Every checkBoxGroup created by repeat is an own control and they are not connected to each other.

Use a simple checkBox control instead and write the selected values in view scope variable array:

<xp:this.beforePageLoad><![CDATA[#{javascript:
    if (!viewScope.selected) {
        viewScope.selected = new Array(viewScope.choices.length);
    }
}]]></xp:this.beforePageLoad>
<xp:repeat
    id="repeat4"
    rows="100"
    value="#{javascript:viewScope.choices}"
    indexVar="rownumber"
    var="row"
    first="0">
    <xp:panel
        id="panelCheckBox"
        style="display: inline-block;">
        <xp:checkBox
            id="checkBox1"
            text="#{row[0]}"
            value="#{viewScope.selected[rownumber]}"
            checkedValue="#{row[0]}"
            uncheckedValue="#{javascript:''}" />
    </xp:panel>
    <xe:tooltip
        id="tooltip1"
        for="panelCheckBox"
        position="below"
        label="#{row[1]}" />
</xp:repeat>

The result is in viewScope.selected then.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Seems to work this way , but checkboxes are displayed 1 per line. I need them to be displayed on 1 line. When I wrapped a table around it I was surprised that the tooltip only displayed when I hover over the box and not when I hover over the text of the checkboxes. I also had to change the for=panelcheckBox into for=checkBox or the tooltip stops working. Any idea how to make it work with hover over text also and display the items horizontally ? – Marc Jonkers Mar 01 '17 at 15:21
  • Give the panel "panelCheckBox" the style `display: inline-block;`. This puts the checkBoxes into one line and still shows tooltip hovering over text. – Knut Herrmann Mar 01 '17 at 15:41