Skip to content

Commit

Permalink
fix: modify registrations js to make appear the newsletter modal
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Nov 20, 2023
1 parent 92fbf88 commit d492e5e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/packs/src/decidim/user_registrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ $(() => {
const $cityLivingArea = $(".city_living_area");
const $metropolisLivingArea = $(".metropolis_living_area");
const $railsValidationAsterisk = $("[for=\"registration_user_living_area\"]").children("span.label-required").clone()
const newsletterSelector = 'input[type="checkbox"][name="user[newsletter]"]';
const $newsletterModal = $("#sign-up-newsletter-modal");

const $underageSelector = $("#registration_underage_registration");
const $statutoryRepresentativeEmailSelector = $("#statutory_representative_email");
Expand All @@ -24,6 +26,13 @@ $(() => {
}
};

const checkNewsletter = (check) => {
$userRegistrationForm.find(newsletterSelector).prop("checked", check);
$newsletterModal.data("continue", true);
$newsletterModal.foundation("close");
$userRegistrationForm.submit();
}

if ($underageSelector.is(":checked")) {
emailSelectorToggle();
}
Expand Down Expand Up @@ -120,4 +129,18 @@ $(() => {

$formStepForwardButton.attr("disabled", (checkMandatoryFormField().length > 0));
});

$newsletterModal.find(".check-newsletter").on("click", (event) => {
checkNewsletter($(event.target).data("check"));
});

$userRegistrationForm.on("submit", (event) => {
const newsletterChecked = $userRegistrationForm.find(newsletterSelector);
if (!$newsletterModal.data("continue")) {
if (!newsletterChecked.prop("checked")) {
event.preventDefault();
$newsletterModal.foundation("open");
}
}
});
});

0 comments on commit d492e5e

Please sign in to comment.