Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Richfaces: limit rich:comboBox to values of the value list

Tags:

jsf

richfaces

I've got the following simple comboBox in my page.

<rich:comboBox value="#{groupConfig.group}"
               styleClass="userCombo"
               filterNewValues="false"
               directInputSuggestions="true">
  <f:selectItems value="#{
    workflowConfigCtrl.groupsFor(groupConfig,appNode.approvalTier)
  }" />
</rich:comboBox>

It works marvellously, but sadly it allows input of values that are not part of the suggestionList (which makes sense, as I enabled direct text input.

I want direct text input enabled, so that the user can use the suggestion list to quick filter (from a huge group list which can comprise several 100 groups).

At the same time i don't want the user to enter a value that is not in the list. The current approach checks when the user saves the whole form. Is there any way to limit it earlier?

I tried to do it using a javascript onblur= handler, but i can't find the place where the selectItem list is saved in the dom.

like image 971
DThought Avatar asked Aug 21 '12 10:08

DThought


1 Answers

You can access the comboBox list in javascript by using

#{rich:component('myComboBoxId')}.comboList.itemsText

and/or

#{rich:component('myComboBoxId')}.comboList.itemsValue

and then use jQuery.inArray() to verify if the item is in the list.

like image 154
Kiran K Avatar answered Oct 13 '22 12:10

Kiran K