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