-2

I have this sweetalert triggered on the submit of a form.

<script src="{{ asset('themes/js/sweetalert.min.js') }}"></script>
<script>
    $('.btn-danger').click(function(event) {
        event.preventDefault();
        var form = $(this).parents('#form-delete');
        swal({
            title: "Are you sure?",
            text: "You will not be able to recover this imaginary file!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, delete it!",
            closeOnConfirm: false
        }, function(isConfirm){
            if (isConfirm) form.submit();
        });
    });
</script>

But on clicking confirm I want it to continue submitting the form...

<form action="{{ route('admin.blogs.destroy', $blog->id) }}" method="post" id="form-delete">
    @csrf
    @method('DELETE')
    <div class="btn-group btn-group-sm">
        <a href="{{ route('admin.blogs.edit', $blog->id) }}" class="btn btn-primary">edit</a>
        <button type="submit" class="btn btn-danger">delete</button>
    </div>
</form>

error

1 Answers1

0

The function swal() doesnt accept a second parameter as the callback anymore, user .then()

<script>
    $('.btn-danger').click(function(event) {
        event.preventDefault();
        var form = $(this).parents('#form-delete');
        swal({
            title: "Are you sure?",
            text: "You will not be able to recover this imaginary file!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, delete it!",
            closeOnConfirm: false
        })
        .then(function (isConfirm) {
            if (isConfirm) {
                form.submit();
            }
        });
    });
</script>
N69S
  • 16,110
  • 3
  • 22
  • 36
  • I installed `"realrashid/sweet-alert": "^5.1"` package. and read all docs in https://realrashid.github.io/sweet-alert/install site. – Asharf Khosravi Dec 01 '22 at 10:13