I have an icon of a trash can for a delete button on a Django site.
It's just an anchor tag with an i tag inside that has its href set to a delete view passing the id of the model element.
It works perfectly fine, but I want to create a dialog popup that asks for confirmation before deleting it.
I have seen a few ways to do this but they all require it to be input instead of an anchor.
I also need to make this work on touch devices as well.
How can I change it to an input element and keep the icon as the button rather than showing a submit button. And how can I get the dialog to popup and when Yes is clicked, pass the correct url and id to the submit?
Any advice would be much appreciated.
On the desktop, navigate to the "Recycle Bin" folder. Right-click on the Recycle Bin folder and click on the "Properties" option. "Recycle Bin Properties" window will appear on the screen. Click (select) on the "Display delete confirmation dialog" option and click on the "Apply" button to proceed.
To delete the project you can delete the project folder. But this method is good only if you use SQLite as a database. If you use any other database like Postgresql with Django, you need to delete the database manually. This should delete the folder and it's contents.
Deletes should never be a GET request. It's not less dangerous than the #1 up boated answer, any JavaScript is dangerous if JavaScript is turned off. JavaScript being turned on or off is a user's personal choice, if JavaScript is turned off, the user should know better not to push any buttons on any website.
The easiest way is to add a confirm prompt:
<a ... onclick="return confirm('Are you sure you want to delete this?')">Delete</a>
But you should not do inline javascript so try to add a class and abstract it away. Here it is with jquery:
<a class="confirm-delete" ...>Delete</a>
$(document).on('click', '.confirm-delete', function(){
return confirm('Are you sure you want to delete this?');
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With