0

I'm trying to implement a Reset button that clears all fields back to empty or to some database related default value. Even though my solution actually works, the problem is that this button also intercepts the ENTER key, which is wrong as that should only go to the actual submit button. I have tried three solutions:

<h:commandButton id="x1" value="Clear" action="bean.myAction"/>  - works, but intercepts ENTER key

<h:commandButton id="x1" type="button" value="Clear" action="bean.myAction"/>   - works, but intercepts ENTER key

<h:commandButton id="x1" type="reset" value="Clear" action="bean.myAction"/> - Does NOT call my action on keypress, but does not intercept ENTER key

<h:button does not compile. (wrong jsf version, and I cannot change that)

Looking at the generated code I can see that 'type="button"' still produces a 'submit' type button, which would explain that error, but why does 'type="reset" ' not call my action?

Is there a way to either make the actual submit button (which sits to the right of my clear button) the default, or to make my clear button ignore all except actual mouse-press? Should make it clear that the default 'reset' action is not good enough as that only resets to previous values, and I want Initial values. thanks

user3211098
  • 51
  • 1
  • 10
  • 2
    Does this answer your question? [Default action to execute when pressing enter in a form](https://stackoverflow.com/questions/5485851/default-action-to-execute-when-pressing-enter-in-a-form) – areus Jan 28 '21 at 12:10
  • Thanks, that indeed does the trick: Swap the buttons in HTML and use CSS floats to swap them back. – user3211098 Jan 30 '21 at 21:30

0 Answers0