代码之家  ›  专栏  ›  技术社区  ›  pennstatephil

grails远程表单,多个提交,带有javascript

  •  4
  • pennstatephil  · 技术社区  · 15 年前

    g:formremote 与2 g:actionsubmit 按钮(支持javascript),但多个提交按钮有一个小问题(如下所述: http://www.grails.org/Ajax 在“使用formRemote的多个按钮”下。

    我采取了变通办法,使用2 g:submittoremote onClick (有问题的按钮是accept/reject,我想在reject上加上一个日期,这样它就不会被意外使用)。

    有没有办法让javascript和远程表单中的多个提交按钮和平存在?

    提前谢谢你的帮助。。。

    2 回复  |  直到 15 年前
        1
  •  5
  •   BenMorel Manish Pradhan    11 年前

    你试过那个吗 before 参数?它需要一个JavaScript函数,该函数将在远程函数调用之前执行。就这样用吧:

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

    不管你在 参数将插入到 onclick 属性。通过这种方式,您可以轻松地进行验证、获得确认等,甚至可以在提交Ajax调用之前中断onclick处理。有一个类似的例子 after 参数。

        2
  •  3
  •   chrislatimer    15 年前

    好吧,我不是说这很漂亮,但我只是把它弄得乱七八糟了几分钟,有些东西可能对你有用。就像我说的。。。不是最漂亮的解决方案,但解决办法很少是。。。

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