1 Reply Latest reply on Jun 23, 2011 7:12 AM by Thomas Buckley

    Prevent onkeyup event when input field first gets focus

    Thomas Buckley Newbie

      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" />
          <a4j:support event="onkeyup" ajaxSingle="true" immediate="true" requestDelay="200" 
              actionListener="#{bean.validateAmount}" ignoreDupResponses="true" reRender="main"  />
      

       

       

      Thanks

        • 1. Re: Prevent onkeyup event when input field first gets focus
          Thomas Buckley Newbie

          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" />