Forums Register Login
Regarding "html: reset " button
How can I make reset button to remove displayed validation errors and clear the fields, at the same time.
Now, the reset button, seems to ONLY clear the fields,when there are no
errors displayed, but does not do anything, when errors are being displayed.
Any help..!
The html:reset tag renders a <input type="reset"> tag. Reset does not necessarily clear the form field values. The behavior of this tag is to actually restore the values of form fields to what they had in the initial response. If your response came with non-blank field values, then those values will be restored when you click on the reset button. To see what I mean, try changing the value of a field when you get an error message. Then click on the "reset" button. The field you changed should be changed back to the "wrong" value, not cleared.
To get the behavior you want, you need a submit button, only you'd have the attribute value="Reset", i.e. you'd have something like
<html:submit property="action" value="Reset">
In your action class, you'd process the "Reset" request by clearing out the form field values. Note that you'd also have to skip over any validation code when the "Reset" request is submitted.
Another alternative is to use JavaScript to clear the form fields to avoid making a round-trip to the server just to clear fields (not sure if you can clear the error message thought) but I don't particularly like doing that. In practice, I just leave the error message up, let the user correct any errors and resubmit the form.
Hi Junilu,
Your suggestion did help me, to think of a work around.
As you said, I did use a submit button to get the functionality I need.
I am checking the value of hidden variable in the FormBean for "Reset" in the validate method and clearing the fields and errors.
Thanks alot.
I am having similar problem and I can't make Reset button as submit. If u make more than one submit buttons on page, then first one in the list becomes default for all ENTER hits. In my case, 'Reset' followed by 'Search'. That would mean, user enters data, hits enter and rather than performing valid operation, form gets Reset.
So, is there any other way to handle it...
Default submit buttons is kind of a thorny issue. See these:
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

This thread has been viewed 2087 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 18, 2017 02:21:12.