From b80982ceb0b6914e943cb3581f571cc9d4e37051 Mon Sep 17 00:00:00 2001 From: TeshuKatepalli Date: Fri, 8 Dec 2023 10:25:11 +0530 Subject: [PATCH] Updated the block to buildAutoBlocks --- blocks/order-form/order-form.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/blocks/order-form/order-form.js b/blocks/order-form/order-form.js index dfbee2f..f64c255 100644 --- a/blocks/order-form/order-form.js +++ b/blocks/order-form/order-form.js @@ -1,4 +1,4 @@ -export default function decorate(block) { +export default function buildAutoBlocks(block) { const para = block.innerText; block.innerHTML = para; const forms = block.querySelectorAll('form'); @@ -9,10 +9,12 @@ export default function decorate(block) { form.action = originalUrl.replace(/(\?|&)continue=([^&]*)/, `$1continue=${continueUrl}`); }); const accordions = block.querySelectorAll('.mmg-collapsible'); - accordions.forEach((accordion) => { - accordion.children[0].addEventListener('click', () => { - const content = accordion.querySelector('.content'); - content.style.display = content.style.display === 'none' ? 'block' : 'none'; + if (accordions.length > 0) { + accordions.forEach((accordion) => { + accordion.children[0].addEventListener('click', () => { + const content = accordion.querySelector('.content'); + content.style.display = content.style.display === 'none' ? 'block' : 'none'; + }); }); - }); + } }