Reputation: 30207
I have a form with Validations already in place, When i submit the form I have shown bootstrap Modal Window, Know The modal window has two buttons accept and cancel, On click of Accept button i want form to be submit and on cancel close the modal.
var errorMessages = [];
$("#f").submit(function(event){
$("input,select,textarea").not("[type=submit]").each(function (i, el) {
errorMessages = errorMessages.concat(
$(this).triggerHandler("validation.validation")
);
});
if(errorMessages.length==0){
$('#myModal').modal("show");
$("#agreesubmit").on('click',function(){
$("#myModal").modal("hide");
return true;
});
}
event.preventDefault();
});
Now i am stuck at the click of #agreesubmit button when i click it, i want the form to submit and not sure what to do here.
Upvotes: 0
Views: 1735
Reputation: 2217
Does this help? basically you need a "flag" to say the agreement was made, and then submit the form. I've shown a data-attribute being used as it's neat and simple. I've not tested this code but it's logically sound.
$('#f').on('submit', function(e) {
if( $(this).data('form-agree') !== true ) {
e.preventDefault();
// fire modal logic here.
}
});
$('#agreesubmit').on('click', function() {
$('#f').data('form-agree', true).submit();
});
Upvotes: 1