From 759489dc785612cb0651f5d137c82bbe4ab949d5 Mon Sep 17 00:00:00 2001 From: Elizabeth Dunphy Date: Wed, 17 Jul 2019 13:46:49 +0200 Subject: [PATCH 1/3] [BUGFIX] add promise to invisible callback --- Resources/Public/JavaScript/captcha.js | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Resources/Public/JavaScript/captcha.js b/Resources/Public/JavaScript/captcha.js index ddc5d87..b0b7f5b 100644 --- a/Resources/Public/JavaScript/captcha.js +++ b/Resources/Public/JavaScript/captcha.js @@ -66,12 +66,14 @@ let activeButton = null; function submitForm() { let formId = activeButton.name.match('((\\w|\\d)+-)+(\\w|\\d)+')[0]; - let form = document.querySelector('form#' + formId); - let hiddenField = document.createElement('input'); - hiddenField.name = activeButton.name; - hiddenField.setAttribute('value', activeButton.value); - hiddenField.hidden = true; - form.appendChild(hiddenField); + let form = document.getElementById(formId); + if (activeButton.name && activeButton.value) { + let hiddenField = document.createElement('input'); + hiddenField.name = activeButton.name; + hiddenField.setAttribute('value', activeButton.value); + hiddenField.hidden = true; + form.appendChild(hiddenField); + } form.submit(); } @@ -79,13 +81,17 @@ function submitForm() { * add token to inputs and submit form * * @param token + * @returns {Promise|Promise|u} */ function invisibleCallback(token) { - if(activeButton) { - setValuesForRecaptchas(token); - submitForm(); - activeButton = null; - } + return new Promise(function(resolve) { + if (activeButton) { + setValuesForRecaptchas(token); + submitForm(); + activeButton = null; + resolve(); + } + }); } /** From 6ed9c43e0e66ff22e895a4627102fdf7c1f485ca Mon Sep 17 00:00:00 2001 From: Elizabeth Dunphy Date: Wed, 17 Jul 2019 13:58:36 +0200 Subject: [PATCH 2/3] [BUGFIX] fix condition for including js --- Resources/Private/Fusion/Root.fusion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/Private/Fusion/Root.fusion b/Resources/Private/Fusion/Root.fusion index 48b9298..c9a5ff4 100644 --- a/Resources/Private/Fusion/Root.fusion +++ b/Resources/Private/Fusion/Root.fusion @@ -15,6 +15,6 @@ prototype(Neos.Neos:Page) { path = 'resource://Onedrop.Form.Hubspot/Public/JavaScript/captcha.js' } } - @if.hasFormAndIsLiveAndActive = ${q(node).children('[instanceof Neos.Neos:ContentCollection]').find('[instanceof Onedrop.Form.Hubspot:Content.Form]').is() && node.context.live && Configuration.setting('Onedrop.Form.Hubspot.recaptcha_v2.enableRecaptcha')} + @if.hasFormAndIsLiveAndActive = ${q(node).find('[instanceof Onedrop.Form.Hubspot:Content.Form]').is() && node.context.live && Configuration.setting('Onedrop.Form.Hubspot.recaptcha_v2.enableRecaptcha')} } } From 056c98c1a3c050a8da16d211e135ceecd4db11a8 Mon Sep 17 00:00:00 2001 From: Elizabeth Dunphy Date: Thu, 18 Jul 2019 09:43:54 +0200 Subject: [PATCH 3/3] refactor --- Resources/Private/Translations/de/ValidationErrors.xlf | 2 +- Resources/Public/JavaScript/captcha.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Resources/Private/Translations/de/ValidationErrors.xlf b/Resources/Private/Translations/de/ValidationErrors.xlf index 317bd4e..e7203a8 100644 --- a/Resources/Private/Translations/de/ValidationErrors.xlf +++ b/Resources/Private/Translations/de/ValidationErrors.xlf @@ -5,7 +5,7 @@ Captcha could not be validated. - Captcha konnte nicht validiert werden.. + Captcha konnte nicht validiert werden. diff --git a/Resources/Public/JavaScript/captcha.js b/Resources/Public/JavaScript/captcha.js index b0b7f5b..844fee2 100644 --- a/Resources/Public/JavaScript/captcha.js +++ b/Resources/Public/JavaScript/captcha.js @@ -65,8 +65,7 @@ function rebuildCaptcha() { let activeButton = null; function submitForm() { - let formId = activeButton.name.match('((\\w|\\d)+-)+(\\w|\\d)+')[0]; - let form = document.getElementById(formId); + let form = activeButton.closest('form'); if (activeButton.name && activeButton.value) { let hiddenField = document.createElement('input'); hiddenField.name = activeButton.name;