Grails remote form, multiple subordinates, with javascript

I have a situation where I have a form with several submit buttons, and I want to update the remote frame. I tried using g:formremote with 2 g:actionsubmit (which support javascript), but several submit buttons have failed (described here: http://www.grails.org/Ajax in the "Multiple buttons with formRemote" section).

I applied a workaround using the 2 g:submittoremote , which work the way I expect, but do not accept javascript parameters like onClick (the corresponding buttons accept / reject and I want to put AYS on the garbage so that it is not used accidentally) .

Is there a way for javascript and multiple remote submit buttons for a peaceful existence?

Thanks in advance for your help ...

+4
source share
2 answers

Have you tried the before parameter? It executes a JavaScript function that will be executed before the remote function is called. Just use it like this:

 <g:submitToRemote value="Reject" update="feedback" controller="test" action="reject" before="if (!confirm('sure?')) {return false;}" /> 

No matter which JavaScript you put in the before parameter, it will be inserted into the onclick attribute right before the Ajax update call. Thus, you can easily perform validation, receive confirmations, etc. And even give up onclick processing before sending an Ajax call. There is a similar after parameter.

+5
source

Well, I’m not saying that it’s beautiful, but I just messed it up in a few minutes and something that might work for you. As I said ... not the perfect solution, but workarounds are rarely ...

  <html> <head> <g:javascript library="prototype" /> </head> <body> <script type="text/JavaScript"> function setReject() { document.getElementById('reject').value='true' } </script> <g:formRemote name="test" update="updater" url="[ controller: 'date', action: 'test']" > <g:hiddenField name="reject" value="false" /> <g:submitButton name="submit" value="something" onclick="setReject();return confirm('Are you sure???')" /> <g:submitToRemote update="updater" action="otherTest" controller="date" value="Go Ahead"/> </g:formRemote> <div id="updater"> </div> </body> </html> 
+3
source

Source: https://habr.com/ru/post/1313795/


All Articles