Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Regarding "html: reset " button

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..!
 
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Praveen Teegala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Praveen.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
Thanks
 
Junilu Lacar
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Default submit buttons is kind of a thorny issue. See these:
http://lists.w3.org/Archives/Public/www-html/2001Sep/0033.html
http://ppewww.ph.gla.ac.uk/~flavell/www/formquestion.html
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic