嘿伙计们,当用户确认删除时,我对 swal 条件有一个小问题,没有任何反应 (swal版本7.0.7)
有 swal 代码
<form id="del_type" action="{{ route('admin.type.destroy', $type->id) }}" method="post"style="display: inline">
{!! method_field('delete') !!}
{{ csrf_field() }}
<button class="btn btn-danger delete_type" type="submit" >Supprimer</button>
</form>
$(".delete_type").click( function (e) {
e.preventDefault();
var _this = $(this)
//console.info(_this.parent().prop('action'))
swal({
title: "Attention",
text: "Veuillez confirmer la suppression",
type: "warning",
showCancelButton: true,
confirmButtonText: "Confirmer",
cancelButtonText: "Annuler",
}, function(result) {
if(result) {
$('#del_type').submit();
} else {
swal('cancelled');
}
});
});
当我单击删除按钮时,它会显示带有确认和取消按钮的 swal,但是当您单击确认时,什么也没有发生,也没有提交 (抱歉我的英语)
最佳答案
根据官方文档,你必须使用promise并检查result.value
。
https://sweetalert2.github.io/v7.html
所以,尝试稍微重写一下,就像这样:
Swal({
title: "Attention",
text: "Veuillez confirmer la suppression",
type: "warning",
showCancelButton: true,
confirmButtonText: "Confirmer",
cancelButtonText: "Annuler",
}).then((result) => {
if (result.value) {
$('#del_type').submit();
} else {
swal('cancelled');
}
})
关于javascript - 无法在 Laravel 上使用 swal 确认删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58879214/