beginner
beginner

Reputation: 190

Combo box return relevant information depends on the edit box's value

Here is what I intend to do in xpages.

When I type something in the edit box, then I click the button, the combo box will display relevant information.

Here is the design in xpage, there is a edit box, a button and a combo box. The edit box uses session scope variable, the button is used to partial refresh the combo box. The combo box displays relevant values depends on the edit box value.

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:inputText id="inputText1" value="#{sessionScope.itemname}"></xp:inputText>
<xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="partial" refreshId="comboBox1">
    </xp:eventHandler></xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:comboBox id="comboBox1">
    <xp:selectItems>
        <xp:this.value><![CDATA[#{javascript:var SetFirstValueBlank = @Text("");
return SetFirstValueBlank;              
}]]></xp:this.value>
    </xp:selectItems>
    <xp:selectItems>
        <xp:this.value><![CDATA[#{javascript:var searchitem= getComponent("inputText1").getValue();
var result = @DbLookup(@DbName(),"itemListView", searchitem,1 ); 
return result;}]]></xp:this.value>
    </xp:selectItems>
</xp:comboBox>
</xp:view>

Suppose in the view, it has many items such as apple, apple chips, apple juice, apple pie, fish, orange, etc.

When I run the program, I type apple pie exactly, the combo box can show the exact value (apple pie) for me to choose, but if I just type appl (not the exact value), the combo box will not show anything. In fact, I think the combo box will show apple, apple chips, apple juice and apple pie for me to choose, but the result let me know that I am wrong.

I revised the code, I guess the combo box does not return anything for selection because I use @DbLookup, so and @DbLookup requires the exact value, so the combo box will not show anything.

The reason I choose to use combo box is it allows the user to select one value only.

I think about @DbColumn but it will return all values from the view column, so I use @DbLookup, but it needs the exact value to lookup.

How can I make the combo box return relevant information depends on the edit box's value.

Grateful for your advice please. Thank you.

Upvotes: 1

Views: 95

Answers (2)

Cameron Gregor
Cameron Gregor

Reputation: 1460

instead of using a inputText + combo, have you considered using a control that provides this sort of behavior in the one control?

if you are able to use the extension library, you could use the dojo filteringselect control or dojo combobox control.

both are similar to each other but for dojo filtering select, you must choose a value from the given select list. for dojo combobox you are allowed to also type any word even if it is not in the list

here is an example from Brad Balassaitis's blog https://www.google.com.au/amp/s/xcellerant.net/2013/09/18/xpages-dojo-filtering-select/amp/?client=safari

by default, the entries are matched with a 'starts with' style, so 'pie' would not match 'apple pie' but 'app' would.

if you want filtering select to match any part of the word then you set the queryExpr as follows

<xe:djFilteringSelect id="djFilteringSelect1" value="#{viewScope.myvalue}" autoComplete="false">
    <xe:this.queryExpr><![CDATA[${javascript:"*$\{0}*"}]]></xe:this.queryExpr>
    <xp:selectItems id="selectItems1" value="#{myBean.mySelectItems}"/>
</xe:djFilteringSelect>

Upvotes: 1

Knut Herrmann
Knut Herrmann

Reputation: 30970

Use view's getAllEntriesByKey() with parameter exact set to false to get all entries which start with the given key (in your example "apple").

Upvotes: 1

Related Questions