Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a confirmation popup for class.DeleteView

I am looking to create a confirmation popup window whenever the delete button is clicked. It currently is functional and immediately deletes. Here is some of my code: views.py:

class patientDelete(LoginRequiredMixin, DeleteView):
    model = patient
    success_url = reverse_lazy('patients:index')

index.html

<form action="{% url 'patients:patient-delete' patient.id %}" method="post" style="display: inline;">
    {% csrf_token %}
    <input type="hidden" name="patient_id" value="{{ patient.id }}" />
    <button type="submit" class="btn btn-default btn-sm">
        <span class="glyphicon glyphicon-trash"></span>
    </button>
</form>

and my urls.py

# /patients/patient/pk/delete
url(r'patient/(?P<pk>[0-9]+)/delete/$', views.patientDelete.as_view(), name='patient-delete'),

I have searched left, right and center and dont really understand most of it. I have been using a lot of tutorials to help me here and am quite new to django. Thanks for your help in advance!

like image 886
Rudra Mutalik Avatar asked Sep 01 '17 12:09

Rudra Mutalik


People also ask

How do you make a confirmation pop up in HTML?

The confirm() method displays a dialog box with a message, an OK button, and a Cancel button. The confirm() method returns true if the user clicked "OK", otherwise false .

How do you create a confirmation delete popup in react?

App Component: toISOString(). slice(0, 10); const newToDo = { task: inputValue, id: ide, date: date }; setToDos([... todos, newToDo]); setInputValue(""); }; const handleDelete = (id) => { setPopup(true); let filteredData = todos. filter((todo) => todo.id !==


1 Answers

You can use the javascript confirm method inside the onclick attribute of your <button>:

<button type="submit" class="..." onclick="return confirm('Are you sure?');">

You can read more about how return inside onclick works here.

like image 198
ikkuh Avatar answered Oct 18 '22 17:10

ikkuh