Skip to content

Commit

Permalink
Tidy save addresses JS
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Jul 11, 2023
1 parent 48ff778 commit dce9be6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
33 changes: 18 additions & 15 deletions example-templates/dist/shop/checkout/options.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

{% if saveAddressCheckboxesShown %}
<div class="js-save-address {{ cart.getCustomer() and cart.getCustomer().getIsCredentialed() ? '' : 'hidden' }}">
{{ _self.docs('Saving addresses on order complete.', 'https://docs.craftcms.com/commerce/api/v4/craft-commerce-elements-order.html#registeruseronordercomplete') }}
{{ _self.docs('Saving addresses on order complete.', '#') }}
</div>
{% endif %}

Expand All @@ -96,19 +96,22 @@
</div>

{% js %}
const registerCheckbox = document.querySelector('#registerUserOnOrderComplete');
registerCheckbox.addEventListener('change', () => {
// if the register checkbox is checked make sure the save address checkboxes are visible
const saveAddressBoxes = document.querySelectorAll('.js-save-address');
if (registerCheckbox.checked) {
saveAddressBoxes.forEach((box) => {
box.classList.remove('hidden');
});
} else {
saveAddressBoxes.forEach((box) => {
box.classList.add('hidden');
});
}
});
const $registerCheckbox = document.querySelector('#registerUserOnOrderComplete');

if ($registerCheckbox) {
$registerCheckbox.addEventListener('change', () => {
// if the register checkbox is checked make sure the save address checkboxes are visible
const saveAddressBoxes = document.querySelectorAll('.js-save-address');
if ($registerCheckbox.checked) {
saveAddressBoxes.forEach((box) => {
box.classList.remove('hidden');
});
} else {
saveAddressBoxes.forEach((box) => {
box.classList.add('hidden');
});
}
});
}
{% endjs %}
{% endblock %}
33 changes: 18 additions & 15 deletions example-templates/src/shop/checkout/options.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

{% if saveAddressCheckboxesShown %}
<div class="js-save-address {{ cart.getCustomer() and cart.getCustomer().getIsCredentialed() ? '' : 'hidden' }}">
{{ _self.docs('Saving addresses on order complete.', 'https://docs.craftcms.com/commerce/api/v4/craft-commerce-elements-order.html#registeruseronordercomplete') }}
{{ _self.docs('Saving addresses on order complete.', '#') }}
</div>
{% endif %}

Expand All @@ -96,19 +96,22 @@
</div>

{% js %}
const registerCheckbox = document.querySelector('#registerUserOnOrderComplete');
registerCheckbox.addEventListener('change', () => {
// if the register checkbox is checked make sure the save address checkboxes are visible
const saveAddressBoxes = document.querySelectorAll('.js-save-address');
if (registerCheckbox.checked) {
saveAddressBoxes.forEach((box) => {
box.classList.remove('hidden');
});
} else {
saveAddressBoxes.forEach((box) => {
box.classList.add('hidden');
});
}
});
const $registerCheckbox = document.querySelector('#registerUserOnOrderComplete');

if ($registerCheckbox) {
$registerCheckbox.addEventListener('change', () => {
// if the register checkbox is checked make sure the save address checkboxes are visible
const saveAddressBoxes = document.querySelectorAll('.js-save-address');
if ($registerCheckbox.checked) {
saveAddressBoxes.forEach((box) => {
box.classList.remove('hidden');
});
} else {
saveAddressBoxes.forEach((box) => {
box.classList.add('hidden');
});
}
});
}
{% endjs %}
{% endblock %}

0 comments on commit dce9be6

Please sign in to comment.