Prevent duplicate form actions from happening

XMLWordPrintable

    • 10
    • 4
    • Severity 3 - Minor
    • 0

      Issue Summary

      Currently, it's possible to click on form submissions multiple times and have Jira post duplicate data in the database.

      For example, if a user clicks on Log Work multiple times ( probably because the server responds slowly ), Jira will enter duplicate entries.

      Steps to Reproduce

      1. In an issue, click the More > Log Work
      2. Enter Time Spent
      3. Double click / Spam the Log button

      Expected Results

      Log button to grey out like it did in 9.12.6 / 5.12.6

      Actual Results

      The button doesn't grey out and accept multiple click which in turn creates multiple entries

      Workaround

      Add this code to your Announcement banner:

      <script>
      (function() {
          // Workaround for JRASERVER-78779
          // use a MutationObserver to detect when the button appears in the
          // DOM (it's loaded via AJAX), then attach a one-time click guard directly to it.
      
          function guardButton(btn) {
              if (btn.dataset.guardApplied) return;
              btn.dataset.guardApplied = 'true';
      
              btn.addEventListener('click', function handler(e) {
                  // After first click, disable the button immediately
                  setTimeout(function() {
                      btn.disabled = true;
                      btn.style.opacity = '0.5';
                  }, 0);
      
                  // Re-enable if the form comes back with validation errors
                  // FormDialog2 replaces the dialog content on error, which removes
                  // and re-adds the button - the MutationObserver will re-guard it
              });
          }
      
          function checkAndGuard() {
              var btn = document.getElementById('log-work-form-submit');
              if (btn) guardButton(btn);
          }
      
          // Watch for the button being added to the DOM (dialog loads via AJAX)
          var observer = new MutationObserver(function(mutations) {
              for (var i = 0; i < mutations.length; i++) {
                  var added = mutations[i].addedNodes;
                  for (var j = 0; j < added.length; j++) {
                      if (added[j].nodeType !== 1) continue;
                      // Check if the button is the added node or inside it
                      if (added[j].id === 'log-work-form-submit') {
                          guardButton(added[j]);
                      } else if (added[j].querySelector) {
                          var btn = added[j].querySelector('#log-work-form-submit');
                          if (btn) guardButton(btn);
                      }
                  }
              }
          });
      
          observer.observe(document.body, { childList: true, subtree: true });
      
          // Also guard if already present on page load
          checkAndGuard();
      })();
      </script>
      

      We strongly recomment testing this workaround in a staging or UAT environment before adding it to production.
      If any UI problems happen due to the announcement banner, you can use this procedure to remove it: Resolve Announcement Banner Issues via Database

              Assignee:
              Unassigned
              Reporter:
              Johnny (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated: