5 Replies Latest reply on Jul 21, 2009 11:12 AM by orik

    suggestionBox selection (using Enter key) submits the form

    orik

      Hi,
      When selecting one of the suggestions using the keyboard, with the Enter key, the form which encapsulates the suggestionBox is submitted.

      I'm using richfaces 3.3.1, and this is happening on both FF and IE.

      I was unable to find a bug for this.

      Anyone else encountered this?
      Suggestions?

        • 1. Re: suggestionBox selection (using Enter key) submits the fo
          ilya_shaikovsky
          • 2. Re: suggestionBox selection (using Enter key) submits the fo
            orik

            This only happens when hitting enter submits the form regardless if it contains the suggestion box or not (e.g. have a command button with type="submit").
            The problem is that while hitting enter on "regular" input texts submits the form is default behavior, hitting enter on a selection in the suggestion box should not submit the form.

            Here is a sample code that will submit the form when hitting enter on the suggest box selection :

            <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
            <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
            <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
            <html>
            <head>
            <title>test</title>
            </head>
            
            <body>
            <f:view>
             <h:form id="testForm">
             <h:inputText id="dummyInput" value="dummy" />
             <h:panelGroup>
             <h:inputText style="margin:0px;" id="inputText"
             value="#{BackingBean.inputProp}" />
             <h:graphicImage value="/images/arrow.png" height="14"
             onclick="#{rich:component('inputTextSuggestion')}.callSuggestion(true)"
             alt="" />
             </h:panelGroup>
             <h:outputText id="inputTextObjects" style="font-weight:bold" />
             <rich:suggestionbox height="200" width="200"
             usingSuggestObjects="true"
             onobjectchange="printObjectsSelected(#{rich:element('inputTextObjects')}, #{rich:component('inputTextSuggestion')});"
             suggestionAction="#{BackingBean.autocomplete}" var="item"
             for="inputText" fetchValue="#{item}" id="inputTextSuggestion"
             tokens=",">
             <h:column>
             <h:outputText value="#{item}" />
             </h:column>
             </rich:suggestionbox>
             <h:commandButton value="Submit Button" type="submit" />
             </h:form>
            </f:view>
            </body>
            </html>
            


            • 3. Re: suggestionBox selection (using Enter key) submits the fo
              ilya_shaikovsky

              so just catch the event and use Event.stop(event) or return false;

              • 4. Re: suggestionBox selection (using Enter key) submits the fo
                orik

                Tried using the onselect/oncomplete attributes on the suggestBox tag with not luck.

                Can you please post a sample on how to do that ?

                • 5. Re: suggestionBox selection (using Enter key) submits the fo
                  orik

                  Please disregard previous post,
                  I was able to disable form submit using
                  onselect="Event.stop(event);" as you suggested.

                  Thanks for your help.