Need return value from SweetAlert for confirm an action delete

1.3k Views Asked by At

I have a button for deleting one row

<a href="<?php echo base_url('sekertaris_controller/f1_delete/'); echo $row->kode_f1;?>" onclick="return dialog()"><button class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></button></a>

and using javascript dialog() for trigger link

<script>
    function dialog() {
        swal({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then(function() {
            swal(
                'Deleted!',
                'Your file has been deleted.',
                'success'
            )

        });

    }
</script>

the problem is SweetAlert closed and data in row deleted without confirm

1

There are 1 best solutions below

0
On
function dialog() {
    swal({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
        cancelButtonText: 'Cancel',
        closeOnConfirm: false,
        closeOnCancel: false
    }, function (isConfirm) {
        if (isConfirm) {
            swal("Deleted!", "Your imaginary file has been deleted.", "success");
        } else {
            swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
    });
}