From d1db7e74fecc32cf01280510309c4616ee75b28e Mon Sep 17 00:00:00 2001 From: Tom Conner Date: Wed, 22 Nov 2023 14:37:59 -0500 Subject: [PATCH] no pembroke no pickup --- generator/content/register/stripe-payment.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/generator/content/register/stripe-payment.js b/generator/content/register/stripe-payment.js index dd95b00..12467e3 100644 --- a/generator/content/register/stripe-payment.js +++ b/generator/content/register/stripe-payment.js @@ -123,24 +123,23 @@ document.addEventListener('DOMContentLoaded', async () => { // on address input, save address in localStorage addressElement.on('change', (event) => { console.debug(event);//TODO REMOVE - if (event.complete){ + if (event.error) { + validateAddress(event); + } else if (event.complete) { // Extract potentially complete address const address = event.value; console.debug("address complete"); console.debug(address); setLocalItem("address", JSON.stringify(address)); - validateAddress(); - } - if (event.error) { - showAddressMessage(event.error.message); - } else { - clearAddressMessage(); + validateAddress(null); } }); - function validateAddress() { + function validateAddress(event) { const address = JSON.parse(getLocalItem("address")); - if (!(address.address.city.toLowerCase() === "Pembroke".toLowerCase())) { + if (event && event.error) { + showAddressMessage(event.error.message); + } else if (!(address.address.city.toLowerCase() === "Pembroke".toLowerCase())) { showAddressMessage("Sorry, we can only pick up trees from Pembroke."); return false; } @@ -151,7 +150,7 @@ document.addEventListener('DOMContentLoaded', async () => { const buttonRegister = document.getElementById('button-register'); buttonRegister.addEventListener('click', async (e) => { e.preventDefault(); - if (!validateAddress()) { + if (!validateAddress(null)) { return; } const address = JSON.parse(getLocalItem("address"));