我有一个带有提交按钮的表单,当单击该按钮时,它会打开一个确认模式,这是一个 Twitter Bootstrap 模式。如果单击模态确认按钮,它将提交 for 但验证发生在单击模态按钮而不是表单按钮之后。我也在使用 jQuery 验证
我想让表单首先验证,停止提交,显示确认模式,然后如果确认提交表单。
我意识到这可能是不可能的,但我不知道该怎么做。
<form action="URL" method="POST" id="validation-form" class="confirm-form">
<label for="deletion_reason" class="col-xs-3 col-lg-4 control-label">Select One</label>
<select data-placeholder="Select one..." data-rule-required="true">
<option></option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
</select>
<button type="submit" class="btn btn-danger white-text modal-toggle" data-toggle="modal" data-target="#modal-dialog" data-modal-type="form-confirm" data-modal-title="Delete Transaction" data-modal-text="Are you sure you want to delete this transaction?"><i class="icon-ok"></i> Delete</button>
<a href="http://localhost.testing/form-modals.html"><button type="button" class="btn"><i class="icon-ban-circle"></i> Cancel</button></a>
</form>
$('.modal-toggle').click(function(e){
// modal data assigned
modalType = $(this).data('modal-type').toLowerCase();
modalTitle = $(this).data('modal-title');
modalText = $(this).data('modal-text');
// check which buttons to output
if(modalType == "confirm"){
modalUrl = $(this).data('modal-confirm-url');
modalOptions = '<a href="' + modalUrl + '" class="btn btn-primary showhouse-colour"><i class="icon-ok"></i> Yes</a><button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-ban-circle"></i> No</button>';
}else if(modalType == "alert"){
modalOptions = '<button class="btn btn-primary showhouse-colour" data-dismiss="modal" aria-hidden="true"><i class="icon-ok"></i> Ok</button>';
}else if(modalType == 'form-confirm'){
modalOptions = '<button class="btn showhouse-colour white-text" data-dismiss="modal" id="confirm-form-yes"><i class="icon-ok"></i> Yes</button><button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-ban-circle"></i> No</button>';
}
// output modal footer buttons
$('.modal-title').html(modalTitle);
$('.modal-text').html(modalText);
$('.modal-footer').html(modalOptions);
// if form-confirm, submit it
$('#confirm-form-yes').click(function(){
$('.confirm-form').submit();
});
});