我面临着IE的问题,其中表单被提交许多次,w.r.t点击提交按钮的次数。 这是我的流程..
-> User enters the data in the form and upon click of submit button, will validate
the from
-> if form data is valid, will open a bootstrap confirm request modal to show the data that was
entered and will provide another confirm submit button..when users clicks on
Confirm Submit button, will submit the form
到目前为止一切正常,但是当我们关闭确认请求引导模式并再次单击提交时,接下来单击模式上的确认提交按钮,表单将被提交两次..
所以基本上当我们关闭确认请求模式并重做同一个提交过程一次又一次(意味着关闭确认reqeust模态并点击init提交按钮),然后当我们点击模式上的confrim提交按钮时,根据提交按钮的点击次数,表单提交了许多次...
** its happening only in IE**
我的init提交按钮代码:
<div class="form-group actionBtnGrp">
<div class="col-sm-offset-5 col-sm-7">
<button type="reset" class="btn btn-form-action btn-primary-grey resetFormData">
<spring:message code="cancel"></spring:message>
</button>
<button type="submit" class="btn btn-form-action btn-primary-sub formSubmitBtn" id="saveBtn">
<spring:message code="submit"></spring:message>
</button>
</div>
</div>
我的确认模式 - 确认提交按钮
<div class="modal-footer">
<button type="button" id="subForm"class="btn btn-primary-sub">Confirm
Request</button>
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Cancel</button>
</div>
我的jquery提交代码:
$("#policy-form").on('submit', function(event){
var isvalidate=$('#policy-form').valid(); //calling validation method and doing validation
if(isvalidate) {
if(!$("#confirm-request").data('bs.modal') || $("#confirm-request").data('bs.modal').isShown != true) { //checking confirm modal is open and opening
$("#confirm-submit").modal('show');
$('#subForm').text('Confirm Request')
.prop('disabled', false);
event.preventDefault ? event.preventDefault() : (event.returnValue = false);
}
}
});
confrim请求模式打开并执行某些操作并且atlast将有confrim提交按钮以提交请求..
$('#confirm-request').on('show.bs.modal', function (e) { // confirm request bootstrap modal
..//// doing something else
// finally submitting the request upon clicking confirm submit from
$('#subForm').click(function () {
$(this).text('Submitting ...')
.prop('disabled', true);
$('#policy-form').submit(); // submitting the form..
});
如上所述,一旦又一次关闭并重新打开bootstrap模式,将多次提交表单。(当我们点击cofirm提交按钮时...... IE缓存提交按钮的点击次数然后提交那么多次......?)
任何帮助真的很感激,因为从昨天起就对此感到震惊。
感谢..
答案 0 :(得分:0)
它看起来不像IE问题。这是click
绑定的问题。您正在将click
处理程序绑定到on
的回调内的元素。这意味着每次显示模态时都会绑定一个新的处理程序。
$('#confirm-request').on('show.bs.modal', function (e) { // confirm request bootstrap modal
..//// doing something else
// finally submitting the request upon clicking confirm submit from
$('#subForm').click(function () {
$(this).text('Submitting ...')
.prop('disabled', true);
$('#policy-form').submit(); // submitting the form..
});
让它看起来像这样
$('#subForm').click(function () {
$(this).text('Submitting ...')
.prop('disabled', true);
$('#policy-form').submit(); // submitting the form..
});
$('#confirm-request').on('show.bs.modal', function (e) { // confirm request bootstrap modal
..//// doing something else
// finally submitting the request upon clicking confirm submit from