1

I've a reset button on my GSP to reset form fields to default values, so calling controller action upon clicking reset button and have to set params to blank and need to render same view.

I'm trying.. Controller Action:

def reset = {
   request['name']= ''
   request['street']= ''
   render(view:'employee')
}

GSP:

<input type="text" id="name" value="${params.name}">

But it seems to be not working... how to achieve this?

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
TP_JAVA
  • 1,002
  • 5
  • 23
  • 49
  • Why dont you just reset it at html layer? if you have a form, do reset on the form. – Alidad Apr 15 '13 at 19:16
  • @Alidad: it is easy but command validation errors are still showing up... – TP_JAVA Apr 15 '13 at 19:24
  • Ok, what you can do, on the reset also call a js method to hide the div including those messages. – Alidad Apr 15 '13 at 19:28
  • @alidad: I thought of doing it but i'm displaying field level messages so multiple divs I've to disable...can't we achieve using grails actions calls to default param values? – TP_JAVA Apr 15 '13 at 19:30
  • The form reset should clear all for you, look at this link http://stackoverflow.com/questions/2086287/how-to-clear-jquery-validation-error-messages, also your can add a class (ex. message) to all your divs and hide them all. – Alidad Apr 15 '13 at 19:36

2 Answers2

0

Depending if you are using jquery or another library it will be something like this:

$("form").on("reset",function(){
      $(".message").hide();
});
Alidad
  • 5,463
  • 1
  • 24
  • 47
  • Nope..it doesn't work...I have checkboxes in my form its only reset to previous state not for the initial state... – TP_JAVA Apr 16 '13 at 15:29
0

Resolved by using redirect in controller action..so that all params and command validations will be out of request scope so no need to reset any fields.

TP_JAVA
  • 1,002
  • 5
  • 23
  • 49