#28889: Use JavaScript to prevent double submission of admin forms
-------------------------------------+-------------------------------------
     Reporter:  Manuel Saelices      |                    Owner:  Marcelo
         Type:                       |  Galigniana
  Cleanup/optimization               |                   Status:  closed
    Component:  contrib.admin        |                  Version:  1.11
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Ömer Faruk Abacı):

 In our production environment, we encountered this issue with inlines.
 Adding an inline object and mistakenly clicking “Save” multiple times
 resulted in multiple requests, leading to the insertion of the same inline
 object multiple times. To resolve this, I disabled the buttons on form
 submission by overriding `admin/submit_line.html` as follows:


 {{{
 {% extends "admin/submit_line.html" %}
 {% block submit-row %}
     <script>
         if (!$){
             const $ = django.jQuery;
         }
         $(document).ready(function() {
             $('form').on('submit', function(event) {
                 $('input[type="submit"], button').prop('disabled', true);
             });
         });
     </script>
     {{ block.super }}
 {% endblock %}
 }}}

 I understand the concerns raised in previous discussions about network
 failures potentially leaving buttons disabled and preventing further user
 actions. However, I believe we need to weigh which scenario is worse:
 adding duplicate entries or requiring users to re-enter their changes.
 Additionally, we should consider which is more likely: mistakenly clicking
 “Save” twice or experiencing a network failure. IMHO, it might be good to
 address this issue to enhance the user experience and data integrity.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/28889#comment:19>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070190114b925e-05cb6339-bb52-4593-8e09-8ae8662388de-000000%40eu-central-1.amazonses.com.

Reply via email to