0

I'm looking for a simple way to confirm a delete of an item (I'm using Laravel 5.3)

I have this code:

<a href="{{url('/deleteProduct')}}<?='/'.$product->id;?>"><span class="glyphicon glyphicon-trash"></span></a>

So when clicking on the link, I call the route deleteProduct/{id}. But what I want is, that when clicking on the link, there is a prompt, saying something like sure to delete? yes/no. Only when clicking yes, this route is called then.

I tried it with a bootstrap modal and in general it worked, but I had problems with the $product, actually $product is an item in a foreach, so around the <a>-tag, there is a @foreach($products as $product). That's why the modal didn't work, because it got somehow messed up with this foreach (actually $product always held the last "product", because i defined it after the foreach).

Is there a easy to achieve what I want? Alternatively I could create a modal for every product, but there could be up to thousands of those, so this would be nonsense. So whats the better way?

Edit: The normal javascript function confirm() would work, but thats a little "too basic", so I want something that fits in the design, so something with bootstrap would be nice, or anything thats not a alert dialog with two buttons. The functionality of confirm is the one that I want. But also, confirm provides the buttons in english, I may want to customize those to be used in more then one language.

user5638730
  • 495
  • 2
  • 9
  • 22
  • 1
    http://stackoverflow.com/questions/10462839/javascript-confirmation-dialog-on-href-link – IvanMalenko Nov 03 '16 at 20:31
  • @ZakariaAcharki Basically, I want to have something that looks a little bit more nice then something like a alert dialog with two buttons (so the basic js `confirm`). I'm gonna edit my question to include this info. – user5638730 Nov 03 '16 at 20:35
  • You can use any js confirm plugin (for angular, react, jQuery etc.). For example: https://craftpip.github.io/jquery-confirm/ (see section with "Quick use" with button "Goto twitter"). – IvanMalenko Nov 03 '16 at 20:46

1 Answers1

0

I have achieved a pretty great results with SweetAlert plugin. There is actually an example of a delete with ajax. Check it out!

Vitalij
  • 658
  • 8
  • 22