|
1 | 1 | (function (Drupal, once) { |
2 | 2 | Drupal.behaviors.wetWebformPrevBypass = { |
3 | | - attach: function (context) { |
| 3 | + attach(context) { |
| 4 | + |
4 | 5 | // Find Previous button with attribute. |
5 | | - var elements = once('wetWebformPrevBypass', '[data-wet-skip-validation]', context); |
| 6 | + const elements = once( |
| 7 | + 'wetWebformPrevBypass', |
| 8 | + '[data-wet-skip-validation]', |
| 9 | + context |
| 10 | + ); |
6 | 11 |
|
7 | | - elements.forEach(function (el) { |
8 | | - // Runs BEFORE jQuery/WET handlers. |
| 12 | + elements.forEach((el) => { |
9 | 13 | el.addEventListener('click', function (e) { |
10 | | - var form = el.form; |
| 14 | + const form = el.form; |
11 | 15 | if (!form) { |
12 | 16 | return; |
13 | 17 | } |
|
17 | 21 | e.stopImmediatePropagation(); |
18 | 22 | e.stopPropagation(); |
19 | 23 |
|
20 | | - // Native submit: does NOT trigger jQuery submit handlers, |
21 | | - // so no WET validation, but Drupal still processes "op". |
| 24 | + // Remove any earlier injected helper input. |
| 25 | + const existing = form.querySelector('input[data-wet-prev-helper="1"]'); |
| 26 | + if (existing) { |
| 27 | + existing.remove(); |
| 28 | + } |
| 29 | + |
| 30 | + // Preserve the clicked submit button, because form.submit() |
| 31 | + // does not include submit button name/value automatically. |
| 32 | + if (el.name) { |
| 33 | + const hidden = document.createElement('input'); |
| 34 | + hidden.type = 'hidden'; |
| 35 | + hidden.name = el.name; |
| 36 | + hidden.value = el.value; |
| 37 | + hidden.setAttribute('data-wet-prev-helper', '1'); |
| 38 | + form.appendChild(hidden); |
| 39 | + } |
| 40 | + |
22 | 41 | form.submit(); |
23 | 42 | }, true); |
24 | 43 | }); |
|
0 commit comments