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!
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 .
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 !==
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.
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