gigaZhang / struts2-jquery

Automatically exported from code.google.com/p/struts2-jquery
0 stars 0 forks source link

Prevent form submit is not working when the sj has validateFunction #1087

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
According to http://code.google.com/p/struts2-jquery/source/detail?r=1559 the 
form can be prevent to be submitted as:

<script type="text/javascript">
    $.subscribe('beforeSubmit', function(event,data) {
        event.originalEvent.options.submit = checkuser();          
    });
</script>

<sj:submit value = "SUBMIT" 
  onBeforeTopics = "beforeSubmit"
/> 

However if the form has validateFunction then the  event.originalEvent.options 
will not prevent the ajax validation stop! Is there any way we can stop ajax 
validation too.

Original issue reported on code.google.com by afattah...@gmail.com on 19 Mar 2014 at 12:06

GoogleCodeExporter commented 9 years ago
I have seen this request at 
https://code.google.com/p/struts2-jquery/issues/detail?id=1039&can=1&q=client%20
side&sort=-id%20-type&colspec=ID%20Type%20Status%20Priority%20Milestone%20Compon
ent%20Stars%20Owner%20Summary

It seems the solution is simple:
At jquery.struts2.js line 1221, replacing

if (o.validate )

with 

if (o.validate && orginal.options.submit) 

and then in your forms you can do as:

$.subscribe("beforeFormSubmit", function(event, data) {

  if (anyError)
      event.originalEvent.options.submit = false ;
})

This future will allow users to make client side and server side validation 
together.

Original comment by afattah...@gmail.com on 17 May 2014 at 1:43