Xpages add values into Combo Box

后端 未结 1 1114
迷失自我
迷失自我 2021-01-24 07:58

I have a Combo Box and I would like to have the possibility to add new values in the Combo Box using a button and an Input Field. I tried with:

var value = getCo         


        
相关标签:
1条回答
  • 2021-01-24 08:30

    Use a viewScope e.g. viewScope.selectItems variable.

    • Use this viewScope as the selectItems list.
    • Add the initial values to it.
    • Later, add a additional new item to this viewScope and then it will appear in combobox's selection item list.

    This is a working example:

    <xp:comboBox
        id="comboBox1"
        value="#{sessionScope.test}">
        <xp:selectItems>
            <xp:this.value><![CDATA[#{javascript:
            if (!viewScope.selectItems) {
                viewScope.selectItems = ["your","initial","values"];
            }
            return viewScope.selectItems;}]]></xp:this.value>
        </xp:selectItems>
    </xp:comboBox>
    <xp:inputText
        id="inputText1"
        value="#{viewScope.newItem}">
    </xp:inputText>
    <xp:button
        value="Add to selectItems"
        id="button1">
        <xp:eventHandler
            event="onclick"
            submit="true"
            refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:
                viewScope.selectItems.add(viewScope.newItem); 
                viewScope.newItem = "";
            }]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>
    
    0 讨论(0)
提交回复
热议问题