Confirmation before deleting record

Asked

Viewed 589 times

1

I have a link that opens a modal asking if the user wants to delete the record. On the link I have a href that calls a route to delete. How could I call this route only if I click the delete button?

Link:

<a id="danger-alert" href="{{ route('admin.categories.destroy', $category) }}"><i class="zmdi zmdi-delete zmdi-hc-lg"></i></a>

Function:

$('#danger-alert').click(function () {
    swal({
        title: "Deseja excluir o registro?",
        //text: "You will not be able to recover this imaginary file!",
        type: "error",
        showCancelButton: true,
        confirmButtonClass: 'btn-danger waves-effect waves-light',
        confirmButtonText: 'Excluir'
    });
});
  • You say block access to the URL if the user tries to access it otherwise?

  • I need to include a button that the user confirms that they want to delete. I am using a Dashboard that has this function ready. When clicking on the link it calls the function through the ID that displays a modal with the cancel or delete button. If he clicks delete continue the execution by calling the route that is in href.

1 answer

0


I was able to find the solution. In the case lib is Sweetalert for Bootstrap

<a id="danger-alert" data-link="{{ route('admin.categories.destroy', $category) }}"><i class="zmdi zmdi-delete zmdi-hc-lg"></i></a>

$('#danger-alert').click(function () {
    swal({
          title: "Tem certeza?",
          type: "error",
          showCancelButton: true,
          confirmButtonClass: "btn-danger",
          confirmButtonText: "Excluir",
          closeOnConfirm: false
    },
    function(){
       window.location.href = $('#danger-alert').attr("data-link");
    });
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.