9

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!

Rudra Mutalik
  • 372
  • 4
  • 17

1 Answers1

16

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.

ikkuh
  • 4,473
  • 3
  • 24
  • 39