Bootstrapvalidator Automatic submission method for AJAX verification is required to click two times to submit successfully

Source: Internet
Author: User

1 $ (' #defaultForm '). Bootstrapvalidator ({2 message: ' This value was not valid ',3 feedbackicons: {4 valid: ' Glyphicon glyphicon-ok ',5 invalid: ' Glyphicon glyphicon-remove ',6 validating: ' Glyphicon Glyphicon-refresh '7                     },8 Fields : {9 acgroupname: {Ten validators: { One notempty: { A message: ' User group name cannot be empty ' -                                 }, - stringlength: { the max:30, - message: ' User group name is too long ' -                                 }, - Remote: { +URL: "<%=BasePath%>/accountgroup/existaccountrepeat ", - message: ' user group name already exists ', + data:{id:function () { A return $ ("#defaultForm input[name= ' id ']"). Val (); at                                     }} -                                 } -                         -                             } -                         }, - acgroupcontent: { in validators:{ - notempty: { to message: ' User group information cannot be empty ' +                                 }, -                             } the                         }, * strategygroupid: { $ validators:{Panax Notoginseng notempty: { - message: ' Policy group cannot be empty ' the                                 }, +                             } A                         }, the                     } + }). On (' Success.form.bv ', function (e) { - if (againsubmit) { $ return; $                     } - Againsubmit = true;  - //Terminate duplicate commit the E.preventdefault (); - //Get Form form ObjectWuyi var $form = $ (e.target); the //Get Bootstrap Validation Object - var bv = $form. Data (' Bootstrapvalidator '); Wu //Using AJAX to submit form form data - $.post ($form. attr (' action '), $form. Serialize (), function (result) { About if (result== ' 1 ') { $ Window.top.layer.alert (' Save success! ', {icon:6, title: ' Hint '},function (index) { - window.top.layer.close (index); - Closelayer (); -                               }); A }else{ + Parent.layer.alert ("Save failed! ", {title:" Hint "}); the againsubmit = false; -                         } $ }, ' json '); the});

You can see the remote there is an AJAX authentication duplicate name, the effect is bootstrapvalidator not wait for Ajax to get the return value of the direct take a default value false leave. So the automatic submission method of the drawback is greatly modified, as follows: can be successful

1 $ (' #defaultForm '). Bootstrapvalidator ({2 message: ' This value was not valid ',3 feedbackicons: {4 valid: ' Glyphicon glyphicon-ok ',5 invalid: ' Glyphicon glyphicon-remove ',6 validating: ' Glyphicon Glyphicon-refresh '7                     },8 Fields : {9 acgroupname: {Ten validators: { One notempty: { A message: ' User group name cannot be empty ' -                                 }, - stringlength: { the max:30, - message: ' User group name is too long ' -                                 }, - Remote: { +URL: "<%=BasePath%>/accountgroup/existaccountrepeat ", - message: ' user group name already exists ', + data:{id:function () { A return $ ("#defaultForm input[name= ' id ']"). Val (); at                                     }} -                                 } -                         -                             } -                         }, - acgroupcontent: { in validators:{ - notempty: { to message: ' User group information cannot be empty ' +                                 }, -                             } the                         }, * strategygroupid: { $ validators:{Panax Notoginseng notempty: { - message: ' Policy group cannot be empty ' the                                 }, +                             } A                         }, the                     } +                 }); - $ (' #defaultForm '). Submit (function () { $ var flag = $ (' #defaultForm '). Data ("Bootstrapvalidator"). IsValid (); $ setTimeout (function () { - var Flag2 = $ (' #defaultForm '). Data ("Bootstrapvalidator"). IsValid (); - if (flag2) { the var $form = $ (' #defaultForm '); - //Using AJAX to submit form form dataWuyi $.post ($form. attr (' action '), $form. Serialize (), function (result) { the if (result== ' 1 ') { - Window.top.layer.alert (' Save success! ', {icon:6, title: ' Hint '},function (index) { Wu window.top.layer.close (index); - Closelayer (); About                                       }); $ }else{ - Parent.layer.alert ("Save failed! ", {title:" Hint "}); - againsubmit = false; -                                 } A }, ' json '); +                         } the }, (+); -});

As you can see, I don't have to commit automatically I wait for the Ajax return value through a deferred processing.

Bootstrapvalidator Automatic submission method for AJAX verification is required to click two times to submit successfully

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.