Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] website_event: Refresh recaptcha on submit event registration form #620

Open
wants to merge 2 commits into
base: 16.0-irc
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions addons/website_event/static/src/js/website_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var EventRegistrationForm = Widget.extend({
var action = $form.data('action') || $form.attr('action');
var self = this;
return ajax.jsonRpc(action, 'call', post).then(async function (modal) {
const tokenObj = await self._recaptcha.getToken('website_event_registration');
let tokenObj = await self._recaptcha.getToken('website_event_registration');
if (tokenObj.error) {
self.displayNotification({
type: 'danger',
Expand All @@ -96,12 +96,17 @@ var EventRegistrationForm = Widget.extend({
$modal.on('click', '.btn-close', function () {
$button.prop('disabled', false);
});
$modal.on('submit', 'form', function (ev) {
$modal.on('submit', 'form', async function (ev) {
ev.preventDefault();
ev.stopPropagation();
$modal.find('.modal-footer > button.btn-primary').prop('disabled', true);
tokenObj = await self._recaptcha.getToken('website_event_registration');
const tokenInput = document.createElement('input');
tokenInput.setAttribute('name', 'recaptcha_token_response');
tokenInput.setAttribute('type', 'hidden');
tokenInput.setAttribute('value', tokenObj.token);
ev.currentTarget.appendChild(tokenInput);
ev.currentTarget.submit();
})
});
}
Expand Down