开发者

Prevent onkeyup event when input field first gets focus

开发者 https://www.devze.com 2023-03-14 00:26 出处:网络
I have a component I want called on each keyup event by the user. The problem is I do not want to call it when the user first tabs into the text box (onfocus).

I have a component I want called on each keyup event by the user.

The problem is I do not want to call it when the user first tabs into the text box (onfocus).

How can I get around this in JSF/Richfaces? Do I need to combine some Javascript to get around it?

<h:inputText id="limit1" value="#{bean.purchaseTypeItem.subPurchaseLimit}" immediate="true">
    <f:converter converterId="javax.faces.BigDecimal" />
    <f:attribute name="fieldRef" value="Purchase Limit1" />开发者_Go百科
    <a4j:support event="onkeyup" ajaxSingle="true" immediate="true" requestDelay="200" 
        actionListener="#{bean.validateAmount}" ignoreDupResponses="true" reRender="main"  />


Found a solution:

I put in a check to prevent the ajax call firing if the user tabbed into the input box. The addition of the extra a4j:support component is to allow the ajax call when tabbing out of the input box.

<h:inputText id="limit1" value="#{bean.purchaseTypeItem.subPurchaseLimit}" immediate="true">
    <f:converter converterId="javax.faces.BigDecimal" />
    <f:attribute name="fieldRef" value="Purchase Limit1" />
    <a4j:support event="onkeyup" ajaxSingle="true" immediate="true" requestDelay="200" 
        actionListener="#{bean.validateAmount}" ignoreDupResponses="true" reRender="main"  
    onsubmit="if(event.keyCode == 9){return false;}" />
    <a4j:support event="onblur" ajaxSingle="true" immediate="true"
    requestDelay="200" actionListener="#{bean.validateAmount}"
    ignoreDupResponses="true" reRender="main" />


Thanks Thomas! The version of your own solution for richfaces 4 JSR-303 (bean validation) is ...

<rich:validator event="keyup" onbeforesubmit="if(event.keyCode == 9){return false;}"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号