2

I have the code below which is just an input box and an image for the p:commandLink. My problem is that when i press the enter key, the page is just refreshed and it doesn't get inside of my submit method. If i click the image instead of hitting the enter key, everything is fine. Also if i change the p:commandLink to a p:commandButton hitting the enter key works too, it's just that my image doesn't look right because a button is there.

How can i get the enter key to submit a form when i'm using a commandLink instead of a commandButton?

<h:form id="searchForm">
  <p:inputText id="searchBoxMember" value="#{searchBacking.anyWords}" />
  <p:watermark for="searchBoxMember" value="Search" />
  <p:commandLink styleClass="searchSubmitImage" ajax="false" action="#{searchBacking.submit}" />
</h:form>
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Catfish
  • 18,876
  • 54
  • 209
  • 353

1 Answers1

0

In your field, you could try:

onKeyDown="if (event.keyCode == 13) {
  this.blur();
  setTimeout(function() {
      jquery or javascript code to target the link and issue a click event).click();
  }, 800);
}"
Zach Jensz
  • 3,650
  • 5
  • 15
  • 30