简体   繁体   English

Grails submitToRemote验证

[英]Grails submitToRemote validation

I use grails submitToRemote to post my form content using AJAx. 我使用grails submitToRemote使用AJAx发布我的表单内容。 I want to validate form content using my own function and if that function returns true execute the grails submittoRemote. 我想使用我自己的函数验证表单内容,如果该函数返回true,则执行grails submittoRemote。

How can I do this? 我怎样才能做到这一点? Any ideas? 有任何想法吗? Maybe binding the function on before and if the value returned is false don't execute the AJAX. 也许在之前绑定函数,如果返回的值为false,则不执行AJAX。 Please help 请帮忙

 <g:submitToRemote  class="button" update="resultset" value="Swarch" action="show" before=" validateForm()" />

function validateForm() {
  var form = dijit.byId('myForm');
        if(form.validate()) {
          return true;
        }else {
          alert('Form contains invalid data.  Please correct first');
          return false;
        }
          return true;
  }

To make things short. 简而言之。 How can i abort the ajax call if the function returns false. 如果函数返回false,我如何中止ajax调用。

To have a custom validation for your submitToRemote tag you can write your condition as follow before="if(!validateForm()) return false;" 要对submitToRemote标记进行自定义验证,可以before="if(!validateForm()) return false;"编写条件如下before="if(!validateForm()) return false;" :

example: 例:

<g:submitToRemote  class="button" update="resultset" value="Swarch" action="show" before="if(!validateForm()) return false;" />

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM