grails remote form, multiple submits, with javascript - Stack Overflow

I have a situation where I have a form with multiple submit buttons and I want to update a remote frame

I have a situation where I have a form with multiple submit buttons and I want to update a remote frame. I've tried using a g:formremote with 2 g:actionsubmit buttons (which support javascript) but the multiple submit buttons have a glitch (described here: under "Multiple buttons with formRemote").

I took the workaround, using 2 g:submittoremote buttons, which work the way I expect, but doesn't accept the javascript parameters like onClick (the buttons in question are accept/reject and I want to put an AYS on the reject so it isn't used accidentally).

Is there a way for javascript and multiple submit buttons in a remote form to exist peacefully?

Thanks in advance for your help...

I have a situation where I have a form with multiple submit buttons and I want to update a remote frame. I've tried using a g:formremote with 2 g:actionsubmit buttons (which support javascript) but the multiple submit buttons have a glitch (described here: http://www.grails/Ajax under "Multiple buttons with formRemote").

I took the workaround, using 2 g:submittoremote buttons, which work the way I expect, but doesn't accept the javascript parameters like onClick (the buttons in question are accept/reject and I want to put an AYS on the reject so it isn't used accidentally).

Is there a way for javascript and multiple submit buttons in a remote form to exist peacefully?

Thanks in advance for your help...

Share Improve this question asked Jun 24, 2010 at 19:53 pennstatephilpennstatephil 1,6533 gold badges25 silver badges47 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Did you try the before parameter? It takes a JavaScript function, which will be executed before the remote function call. Just use it like this:

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

Whatever JavaScript you put in the before parameter will be inserted into the onclick attribute right before your Ajax updater call. This way you can easily do validation, get confirmations etc. and even break from onclick handling before submitting the Ajax call. There is a similar after parameter.

Okay, I'm not saying this is beautiful, but I just messed around with this for a few minutes and have something that might work for you. Like I said... not the prettiest solution, but workarounds rarely are...

 <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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1741821029a4367960.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信