samedi 18 août 2018

How to set the proper delete confirmation in sweetalert2?

Hello guys I'm using sweetalert2, this is functional already but there are some bugs need to be fixed.

bugs:

  1. when i clicked ok the location.reload() will automatically running without hitting OK"

  2. when i clicked cancel the "delete modal is still running"

I don't know the proper way to this.. this my code

$('body').on('click','.delete-category',function(){
            deleteCategory();
        });

        function deleteCategory(id){

           var id = $('body').find('#categoryTable tbody tr.selected .catId').val();
           console.log(id);

            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(isConfirm){
                if (isConfirm) {
                    $.ajax({
                        url: `/asset/category-delete/${id}`,
                        method: 'DELETE',
                        data: { _token: '' },
                        success: function(data){
                            swal(
                                'Deleted!',
                                'Your file has been deleted.',
                                'success' 
                            );
                            location.reload();
                            },
                        error: function(err){
                            swal('Error!','Please report this issue.', 'error');
                        }
                    });
                } else {
                swal("Cancelled","", "error");
                }
            });
        }

I have a problem in cancel and when i click OK.. Hope anyone could improve this. Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire