From d4ff6ec75aa7d32aa84745e05c2c54cfb5bbb709 Mon Sep 17 00:00:00 2001 From: amdi-odoo Date: Tue, 1 Aug 2023 09:34:39 +0000 Subject: [PATCH] [FIX] website_slides: fix content toggle done MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Purpose ======= Fix the traceback which was appearing when toggling as done the content in the course template. Specification ============= The traceback happened because when all the content in the section has been completed, we want to collapse the next section automatically. However in this view the sections aren't collapsable which resulted in calling methods on null HTML elements. Fixing this by checking if HTML elements exists before trying to collapse the next section. Task-3449558 closes odoo/odoo#130633 X-original-commit: 51f82b306ed12dc2c8e32d2a0bd3052f8eed5d2a Signed-off-by: Stéphane Debauche (std) --- .../website_slides/static/src/js/slides_course_page.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/addons/website_slides/static/src/js/slides_course_page.js b/addons/website_slides/static/src/js/slides_course_page.js index 7419d987c28..7f98f4b46d8 100644 --- a/addons/website_slides/static/src/js/slides_course_page.js +++ b/addons/website_slides/static/src/js/slides_course_page.js @@ -24,11 +24,10 @@ export const SlideCoursePage = publicWidget.Widget.extend({ * Collapse the next category when the current one has just been completed */ collapseNextCategory: function (nextCategoryId) { - const $categorySection = document.getElementById(`category-collapse-${nextCategoryId}`); - const $categorySlides = document.querySelector(`ul[id=collapse-${nextCategoryId}]`); - if ($categorySection.getAttribute('aria-expanded') === 'false' && !$categorySlides.classList.contains('show')) { - $categorySection.setAttribute('aria-expanded', true); - $categorySlides.classList.add('show') + const categorySection = document.getElementById(`category-collapse-${nextCategoryId}`); + if (categorySection?.getAttribute('aria-expanded') === 'false') { + categorySection.setAttribute('aria-expanded', true); + document.querySelector(`ul[id=collapse-${nextCategoryId}]`).classList.add('show'); } },