How could it be implemented a popup confirmation when a submit button in a Django form is clicked?
It would help in case the user accidentally clicks on the submit button. I guess it could be done using a JS function with an addEventListener click function. But I don’t know how to code the function itself.
This is a JavaScript issue, and the precise answer will likely depend upon whether you’re using some JS framework and which one.
I don’t have a snippet I can share, but what we’ve done for this type of situation is not create a “submit” button. Instead, we use a regular button, that when clicked, brings up the confirmation dialog. If “Submit” is clicked on it, then the JavaScript does the submission of the form.
Ok, solved. I was placing the <script>...</script> outside the <body>...</body> and the JS was not being read.
I did not realize since I was using a base.html file extended in my html file.