【问题标题】:Cant confirm delete with swal on laravel无法在 laravel 上使用 swal 确认删除
【发布时间】:2020-03-11 17:39:59
【问题描述】:

嘿伙计们,当用户确认删除时,我对 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,但是当您单击确认时没有任何反应并且没有提交 (对不起我的英语)

【问题讨论】:

  • 尝试使用 result.value 而不是 result if(result.value) { $('#del_type').submit(); }
  • 你能在你的回调函数中这样检查吗(结果){ $('#del_type').submit(); }
  • 我解决了我使用的问题 .then 并且知道它正在工作 .then((result) => { if (result.value) { _this.parent().submit(); } else { }

标签: javascript jquery laravel laravel-5 laravel-blade


【解决方案1】:

根据官方文档,你必须使用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');
    }
})

【讨论】:

    【解决方案2】:

    你可以在没有 swal 的情况下做到这一点。

    $(".delete_type").click( function (e) {
        if(!confirm('Do you want to Delete ?')){
                return false;
           }
      $('#del_type').submit();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-09
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      • 2014-12-24
      • 2021-02-25
      • 1970-01-01
      • 2020-03-10
      相关资源
      最近更新 更多