2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Fixed data-members-newsletter when used with checkboxes (#18041)

no refs

When `data-members-newsletter` was used with checkboxes, if no
checkboxes were selected then the backend would subscribe the member to
the default newsletters which is not what we want - We want to subscribe
the members only to the newsletters they have selected
This commit is contained in:
Michael Barrett 2023-09-08 15:12:16 +01:00 committed by GitHub
parent b472ffb39b
commit 7f9ba46ab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,6 +46,14 @@ export function formSubmitHandler({event, form, errorEl, siteUrl, submitHandler}
}
if (newsletterInputs.length > 0) {
reqBody.newsletters = newsletters;
} else {
// If there was only check-able newsletter inputs in the form, but none were checked, set reqBody.newsletters
// to an empty array so that the member is not signed up to the default newsletters
const checkableNewsletterInputs = event.target.querySelectorAll('input[type=checkbox][data-members-newsletter]') || [];
if (checkableNewsletterInputs.length > 0) {
reqBody.newsletters = [];
}
}
fetch(`${siteUrl}/members/api/send-magic-link/`, {