| @@ -101,8 +101,25 @@ | ||
| 101 | 101 | ); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | + * Re-enables the inputs in the given container, following a failed request. | |
| 106 | + * | |
| 107 | + * @since 3.4.5 | |
| 108 | + * | |
| 109 | + * @param {Object} container Container element. | |
| 110 | + */ | |
| 111 | +function convertKitRestrictContentEnableInputs(container) { | |
| 112 | + container | |
| 113 | + .querySelectorAll( | |
| 114 | + 'input[type="text"], input[type="email"], input[type="submit"]' | |
| 115 | + ) | |
| 116 | + .forEach(function (input) { | |
| 117 | + input.removeAttribute('disabled'); | |
| 118 | + }); | |
| 119 | +} | |
| 120 | + | |
| 121 | +/** | |
| 105 | 122 | * Returns whether the heading should be displayed above the login form, which is |
| 106 | 123 | * the case when the modal is used. |
| 107 | 124 | * |
| 108 | 125 | * @since 3.4.2 |
| @@ -267,8 +284,12 @@ | ||
| 267 | 284 | .catch(function (error) { |
| 268 | 285 | if (convertkit_restrict_content.debug) { |
| 269 | 286 | console.error(error); |
| 270 | 287 | } |
| 288 | + | |
| 289 | + // Re-enable inputs and hide loading overlay, so the form can be resubmitted. | |
| 290 | + convertKitRestrictContentEnableInputs(container); | |
| 291 | + convertKitRestrictContentLoading(false); | |
| 271 | 292 | }); |
| 272 | 293 | } |
| 273 | 294 | |
| 274 | 295 | /** |
| @@ -334,8 +355,12 @@ | ||
| 334 | 355 | .catch(function (error) { |
| 335 | 356 | if (convertkit_restrict_content.debug) { |
| 336 | 357 | console.error(error); |
| 337 | 358 | } |
| 359 | + | |
| 360 | + // Re-enable inputs and hide loading overlay, so the form can be resubmitted. | |
| 361 | + convertKitRestrictContentEnableInputs(container); | |
| 362 | + convertKitRestrictContentLoading(false); | |
| 338 | 363 | }); |
| 339 | 364 | } |
| 340 | 365 | |
| 341 | 366 | /** |
| @@ -362,10 +387,8 @@ | ||
| 362 | 387 | // - submit the form. |
| 363 | 388 | if (otpInput.value.length === 6) { |
| 364 | 389 | otpInput.setSelectionRange(0, 0); |
| 365 | 390 | otpInput.blur(); |
| 366 | - document | |
| 367 | - .querySelector('#convertkit-restrict-content-form') | |
| 368 | - .requestSubmit(); | |
| 391 | + otpInput.closest('form').requestSubmit(); | |
| 369 | 392 | } |
| 370 | 393 | }); |
| 371 | 394 | } |