Seam / JSF form represents onclick launch button

I have a search form with a query builder. The developer is activated by the button. Something like that

<h:form id="search_form">
  <h:outputLabel for="expression" value="Expression"/>
  <h:inputText id="expression" required="true" value="#{searcher.expression}"/>
  <button onclick="openBuilder(); return false;">Open Builder</button>
  <h:commandButton value="Search" action="#{searcher.search}"/>
</h:form>

The result is HTML that has both <button/>, and <input type="submit"/>in form. If the user enters a string in the expression field and presses the enter key rather than pressing the submit button, the query builder is displayed when the expected behavior is that the search should be sent. What gives?

+3
source share
3 answers

It is assumed that the button in the HTML form is used to submit the form. Change the button to input type = "button" and this should fix it.

Alternatively, add type = "button" to the button element.

+2

, ID . onkeydown, (javascript), :

  function KeyDownHandler(event)
    {
        // process only the Enter key
        if (event.keyCode == 13)
        {
            // cancel the default submit
            event.returnValue=false;
            event.cancel = true;
            // submit the form by programmatically clicking the specified button
            document.getElementById('searchButtonId').click();
        }
    }

, .

+1

, , .

Try

  • . , , . (, <input type="text" name="bogusField" style="display: none;" />
  • JavaScript (, ). , GUI, (, GWT)
0

Source: https://habr.com/ru/post/1697346/