2 Replies Latest reply on Apr 17, 2008 11:10 AM by elmarweber

    "Enter" Action in SuggestionBox

    elmarweber

      Hello,

      I'm trying to get a notification and execute an action in case a user presses Enter (Return) when typing something into a suggestion box.

      I tried adding it via "a:support "but I could not find the corresponding event.
      A work around via a call to function defined by "a:jsFunction" did not work either because there is no "on*" for this case as far as I have seen.

      Am I missing something, or does anyone have a suggestion how to execute an execute an action when the user presses enter in a suggestion box?

      Many thanks in advance for any tips.

      ciao,
      Elmar

        • 1. Re:
          ybxiang.wolf

          I am finding the same resolutions!!!
          Any sugesstion?

          • 2. Re:
            elmarweber

            Hello,

            OK, shouldn't try stuff so late =)

            Somehow I always worked on the "<rich:suggestionbox>" tag instead the "<h:inputtext>", which of course could not work.

            Here is my solution in case anyone searches for the same:

            On the inputText tag add a call to a javascript function in case of a key press, e.g.:

            <h:inputText value="#{someBean.text}" id="search"
             required="false" autocomplete="off"
             onkeypress="catchReturn(event)" />


            somewhere appropriate define a JavaScript function catchReturn

            /**
             * Catches the return key and executes an action in that case.
             */
            function catchReturn (e) {
             var keycode;
            
             if (window.event) { // IE
             keycode = e.keyCode;
             } else if (e.which) { // real browsers
             keycode = e.which;
             }
            
             if (keycode == 13 || keycode == "13") {
             someReturnAction();
             }
            }



            Finally define someReturnAction() function such that it executes the Java method on return:

            <a:jsFunction name="addItem" reRender="listN" action="#{someBean.yourSubmitFunction}" focus="search" />


            ciao,
            Elmar