Home > OS >  How to submit in swal?
How to submit in swal?

Time:12-01

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 >
        <a href="{{ route('admin.blogs.edit', $blog->id) }}" >edit</a>
        <button type="submit" >delete</button>
    </div>
</form>

error

CodePudding user response:

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>

CodePudding user response:

just follow this Today we will Learn how to implement sweet alert in our laravel application. https://medium.com/@hossain.naime/how-to-implement-sweet-alert-in-laravel-application-7cfe0fe4dd57

  • Related