最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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>
发布评论

评论列表(0)

  1. 暂无评论