From 444733316097dca5eb4ae5f8b3e6a53976850125 Mon Sep 17 00:00:00 2001 From: Tidiane Dia Date: Fri, 16 Sep 2022 12:12:35 +0100 Subject: [PATCH] Fix undefined error when some dropdowns aren't shown in the images index view (#9211) Fixes #9210 --- CHANGELOG.txt | 1 + docs/releases/4.0.2.md | 1 + wagtail/images/templates/wagtailimages/images/index.html | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 08ad9a419b..0ca09e3a55 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -53,6 +53,7 @@ Changelog * Fix: Update alignment and reveal logic of fields’ comment buttons (Steven Steinwand) * Fix: Regression from Markdown conversion in documentation for API configuration - update to correctly use PEP-8 for example code (Storm Heg) * Fix: Prevent 'Delete' link on page edit view from redirecting back to the deleted page (LB (Ben) Johnston) + * Fix: Prevent JS error on images index view when collections dropdown is omitted (Tidiane Dia) 4.0.1 (05.09.2022) diff --git a/docs/releases/4.0.2.md b/docs/releases/4.0.2.md index 27c06b3ebf..6afedefa11 100644 --- a/docs/releases/4.0.2.md +++ b/docs/releases/4.0.2.md @@ -28,3 +28,4 @@ depth: 1 * Update alignment and reveal logic of fields’ comment buttons (Steven Steinwand) * Regression from Markdown conversion in documentation for API configuration - update to correctly use PEP-8 for example code (Storm Heg) * Prevent 'Delete' link on page edit view from redirecting back to the deleted page (LB (Ben) Johnston) + * Prevent JS error on images index view when collections dropdown is omitted (Tidiane Dia) diff --git a/wagtail/images/templates/wagtailimages/images/index.html b/wagtail/images/templates/wagtailimages/images/index.html index f8e1dd30e2..77384a7f7d 100644 --- a/wagtail/images/templates/wagtailimages/images/index.html +++ b/wagtail/images/templates/wagtailimages/images/index.html @@ -15,9 +15,9 @@ const submitFormOnDropdownChange = (dropdownSelector) => { const dropdown = document.querySelector(dropdownSelector); - dropdown.addEventListener('change', () => { - dropdown.form.submit(); - }) + if (dropdown !== null) { + dropdown.addEventListener('change', () => dropdown.form.submit()); + } }; const dropdownSelectors = [ "#collection_chooser_collection_id",