1

I want to delete a row from my table. The deletion will be held by click an anchor tag and it will submit the delete form. But before submitting the form it will show a confirm dialog box.

<tr>
  <td>    
    <a href="javascript:void(0)" onclick="$(this).parent().find('form').submit().confirm("Are you sure?")">Delete</a>
    <form action="{{route('area.destroy',$row->id)}}" method="post">
      @method('DELETE')
      {{csrf_field()}}
    </form>
  </td>
</tr>

How can I write the JS/jQuery code? Also, if I want to use sweet alert how can I do that?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Tusher
  • 23
  • 8

3 Answers3

1

If you are able to modify the code, an easy inline solution can be to throw the alert on the onclick event of a submit button inside your form.

<tr>
    <td>
        <form action="{{route('area.destroy',$row->id)}}" method="post">
            @method('DELETE')
            {{csrf_field()}}
            <button type="submit" onclick="return confirm('Are you sure?')"></button>
        </form>
    </td>
</tr>
Christophe Hubert
  • 2,833
  • 1
  • 12
  • 25
1

You can use SweetAlert with AJAX in Laravel

SweetAlert : check the documents: https://github.com/realrashid/sweet-alert

Form stackoverflow : Delete method with Sweet Alert in Laravel

Compte exemple: https://youtu.be/bE8Err1twRw

Kais Chrif
  • 134
  • 5
0

Try this:

Swal.fire({
   title: 'Yakin ingin menghapus penguji ?',
   text: "You won't be able to revert this !",
   icon: 'warning',
   showCancelButton: true,
   confirmButtonColor: '#3085d6',
   cancelButtonColor: '#d33',
   confirmButtonText: 'Yes, delete it!'
}).then((result) => {
   if (result.isConfirmed) {
      $(`[data-penguji=${id_penguji}]`).parents('.raised.card').remove()
   }
})
ZygD
  • 22,092
  • 39
  • 79
  • 102