Subscription Preferences Toggle - move all on "unsubscribe"

Currently have checkboxes styled to toggles on the email preferences page.

The movement, colors, and disabled features all work.

I am struggling to have the preferences toggles move when “unsubscribe all” is selected.

Currently, the preference options grey out and become disabled, but having the toggles also move is crucial.

Potental Jquery solution that I found:

<script>
$('#globalunsub').click(function (){
 const isChecked = $(this).prop('checked');

 $('input').each(function (){
 $(this).prop('checked', isChecked);
 });
 });

 $('input:not(#globalunsub)').click(function (){
 $('#globalunsub').prop('checked', false);
 });
});
</script>

Hi, @snacks :waving_hand: Thanks for reaching out! And thank you for including those details. Hey, @BarryGrennan @Indra have you managed a customization like what @snacks is describing? Thank you very much for taking a look! — Jaycee

Thanks for mentioning @Jaycee_Lewis!

Hi @snacks,

You can use the HubSpot CMS boilerplate as an default for this to use. Check out the main.js.

The part you are looking for is added below:

(function () {
 // Variables
 var emailGlobalUnsub = document.querySelector('input[name="globalunsub"]');

 // Functions

 // Function to disable the other checkbox inputs on the email subscription system page template
 function toggleDisabled() {
 var emailSubItem = document.querySelectorAll('#email-prefs-form .item');

 emailSubItem.forEach(function (item) {
 var emailSubItemInput = item.querySelector('input');

 if (emailGlobalUnsub.checked) {
 item.classList.add('disabled');
 emailSubItemInput.setAttribute('disabled', 'disabled');
 emailSubItemInput.checked = false;
 } else {
 item.classList.remove('disabled');
 emailSubItemInput.removeAttribute('disabled');
 }
 });
 }

 // Execute JavaScript on document ready
 domReady(function () {
 if (!document.body) {
 return;
 } else {
 // Function dependent on email unsubscribe from all input
 if (emailGlobalUnsub) {
 emailGlobalUnsub.addEventListener('change', toggleDisabled);
 }
 }
 });
})();

Hey Indra, thank you for the update and the potential solution.

I plugged it in but am not having any luck.

Will come back to this later, thank you for your help though.