After jQuery blocks the default submission behavior of the form, what should I do if I want to continue the submission behavior?
The details are as follows:
A delete button, use sweetalert2 to prompt before submission. When the "Confirm" button in the prompt box is pressed, continue to submit the form.
html code:
<form action="/articles/{{ $article->id }}" method="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<input class="btn btn-danger btn-sm need-alert" type="submit" value="删除">
</form>
js code:
<script>
$('.need-alert').on('click', function (event) {
//阻止默认提交事件
event.preventDefault();
//sweetalert2的提示框代码:
swal({
title: '确定要删除吗?',
text: '删除后不能恢复!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: '确认删除'
}).then(function () {
}).catch(swal.noop);
})
</script>
After preventDefault() prevents the default submission event, the sweetalert2 prompt box can pop up normally.
Question:
After clicking "Confirm Delete" in the sweetalert2 prompt box, what should I write if I want to continue submitting this form?
巴扎黑2017-05-16 16:48:27
Bind the click event to the button, implement the pop-up window in the callback function of the event, and determine the pop-up window value selected by the user. If it is true, get the form element to trigger the submission event$("form").submit()
If it is not true, do other corresponding processing
伊谢尔伦2017-05-16 16:48:27
To be fair, if the input type is written as submit, you need to write an additional block to block the default event. If the type is changed to button, there is no need to block the default event. Your confirmation box should have a callback function, maybe in then. You should be able to write submission directly