Skip to content

Commit

Permalink
Merge pull request #5 from 1drop/bugfix/return-promise-in-recaptcha-c…
Browse files Browse the repository at this point in the history
…allback

Bugfix/return promise in recaptcha callback
  • Loading branch information
beardcoder authored Jul 18, 2019
2 parents 547bd5c + 056c98c commit 6cecb4b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Resources/Private/Fusion/Root.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
}
}
2 changes: 1 addition & 1 deletion Resources/Private/Translations/de/ValidationErrors.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- RecaptchaV2Validator -->
<trans-unit id="1536243701" approved="yes">
<source>Captcha could not be validated.</source>
<target xml:lang="de">Captcha konnte nicht validiert werden..</target>
<target xml:lang="de">Captcha konnte nicht validiert werden.</target>
</trans-unit>

<!-- EmailAddressBlacklistValidator -->
Expand Down
29 changes: 17 additions & 12 deletions Resources/Public/JavaScript/captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,32 @@ function rebuildCaptcha() {
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 = activeButton.closest('form');
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();
}

/**
* 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();
}
});
}

/**
Expand Down

0 comments on commit 6cecb4b

Please sign in to comment.