TungHarry
TungHarry

Reputation: 1161

Run ajax listener action when choosing value from autofill list

I use jsf + richfaces + jboss seam. I have code :

<h:inputText id="receiptAmount" style="text-align: right;"
                    value="#{receiptsHome.instance.receiptAmountString}"
                    onkeypress="if((event.which &lt; 48 &amp;&amp; event.which != 8 &amp;&amp; event.which != 26 &amp;&amp; event.which != 44 &amp;&amp; event.which != 46) || (event.which != 127 &amp;&amp; event.which &gt; 57)) return false;">
                    <a:support event="onkeyup" ajaxSingle="true"
                        reRender="receiptAmount1, listContractsDiv"
                        action="#{receiptsHome.setPaymentMoneyForListContracts}" />
                </h:inputText>

But when i work on chrome. I have 2 case as below :

Case 1 : I enter number from keyboard with values : 20000. It run action in a:support tag and reRender red text at right. It's ok : input from keyboard

Case 2 : I does not use keyboard. I use mouse to click from autofill list with similar values : 20000 (browser has save old that value before). It's not run action in a:support tag : enter image description here

How can i choose from autofill list,it's still run action ?

Upvotes: 0

Views: 67

Answers (1)

dognose
dognose

Reputation: 20899

modern browser support oninput (not sure if a4j is supporting this event) which will be fired for both cases: If a key is pressed or if a autocomplete entry is choosen.

If you don't want to rely on this, use autocomplete="off" on the input element. (However I believe some browsers are ignoring this).

If you don't need the data to be processed after each keystroke, the best option would be to use onblur, because no matter if it was typing or an autocomplete selection, there will be a blur event once the input element looses focus again.

Upvotes: 2

Related Questions