This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Mar 11, 2011, 12:12 PM
22 Posts
topic has been resolvedResolved

Can I define label/value pairs for selectitems for a combobox?

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags:
  • Replies: 3
Sorry for this newbie sort of question...
 
I have a combobox on my XPage that is currently defined as follows:
 
 <xp:comboBox id="testing">
 <xp:selectItem itemLabel="label1" itemValue="value1"></xp:selectItem>
 <xp:selectItem itemLabel="label2" itemValue="value2"></xp:selectItem>
</xp:comboBox>
 
 I would like instead to use some script to determine which options are displayed, so I'd like to use something like the following (obviously a very simplified example):
 
<xp:comboBox id="testing">
<xp:selectItems> 
<xp:this.value>
<![CDATA[#{javascript:var options=[];
if(sessionScope.test.indexOf("option1")>-1)  options.push('option1')
if(sessionScope.test.indexOf("option2")>-1)  options.push('option2')
return options;}]]>
</xp:this.value>
</xp:selectItems>
</xp:comboBox> 
 
This works fine, but only allows me to define the labels (which are subsequently treated as values I believe).
Is there something that I can return to segregate the labels/values so that they can differ?
 
Any advice would be greatly appreciated!  T. 
Mar 11, 2011, 2:55 PM
64 Posts
I believe <xp:selectItem> is what you're looking for...
- Note: no "s" on selectItem.  If I recall correctly that lets you define individual items for the select, so you could say use a repeat control on some data, run some code in that repeat, and build an ad-hoc list of selection items.
 
- Also if I recall correctly the XPage doesn't care how the items appear.  Do a repeat (or any XPagey mechanism) and emit standard everyday HTML select markup and it'll work.

Hope this helps...
Mar 11, 2011, 3:45 PM
261 Posts
Re: Can I define label/value pairs for selectitems for a combobox?
On the "Values" properties box of the combobox control, add a "Formula Item". The formula you write should return an array of strings. Every string in the array can have a label and value if you add a pipe (|) character to it, e.g.:
 
[
  "label1|value1",
 "label2|value2"
]
 
In the pre-XPages era, this syntax was also used to add values to a combobox on a Form.
 
Mark
Mar 12, 2011, 1:14 AM
22 Posts
Perfect! Thanks Mark!
I didn't realize that that strategy held over for XPages as well.
Lesson learned - Thanks very much!! 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal