From 58ebfe1fb176eb0fc340b4cd82db4e08387b5c25 Mon Sep 17 00:00:00 2001 From: Adrien Hamraoui Date: Fri, 2 Feb 2024 10:24:26 +0100 Subject: [PATCH] fix: InlinePanel - take 1st child when configuring up and down js events Issue was appearing when there was nested inline panels. currentChild. find would match the parent up/down button but also all the ones of the nested inline panels Fixes #5919 --- CHANGELOG.txt | 1 + CONTRIBUTORS.md | 1 + client/src/components/InlinePanel/index.js | 16 ++++++++++++---- docs/releases/6.1.md | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e8ca73f87a..baaaf14c6b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -12,6 +12,7 @@ Changelog * Fix: Fix typo in `__str__` for MySQL search index (Jake Howard) * Fix: Ensure that unit tests correctly check for migrations in all core Wagtail apps (Matt Westcott) * Fix: Correctly handle `date` objects on `human_readable_date` template tag (Jhonatan Lopes) + * Fix: Ensure re-ordering buttons work correctly when using a nested InlinePanel (Adrien Hamraoui) * Docs: Add contributing development documentation on how to work with a fork of Wagtail (Nix Asteri, Dan Braghis) * Docs: Make sure the settings panel is listed in tabbed interface examples (Tibor Leupold) * Docs: Update multiple pages in the reference sections and multiple page names to their US spelling instead of UK spelling (Victoria Poromon) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0125996b81..f5589800c4 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -798,6 +798,7 @@ * Hossein * Andre Delorme * arshyia3000 +* Adrien Hamraoui ## Translators diff --git a/client/src/components/InlinePanel/index.js b/client/src/components/InlinePanel/index.js index 4094638c6f..c450929286 100644 --- a/client/src/components/InlinePanel/index.js +++ b/client/src/components/InlinePanel/index.js @@ -52,8 +52,10 @@ export class InlinePanel extends ExpandingFormset { const childId = 'inline_child_' + prefix; const deleteInputId = 'id_' + prefix + '-DELETE'; const currentChild = $('#' + childId); - const $up = currentChild.find('[data-inline-panel-child-move-up]'); - const $down = currentChild.find('[data-inline-panel-child-move-down]'); + const $up = currentChild.find('[data-inline-panel-child-move-up]:first '); + const $down = currentChild.find( + '[data-inline-panel-child-move-down]:first ', + ); $('#' + deleteInputId + '-button').on('click', () => { /* set 'deleted' form field to true */ @@ -148,8 +150,14 @@ export class InlinePanel extends ExpandingFormset { forms.each(function updateButtonStates(i) { const isFirst = i === 0; const isLast = i === forms.length - 1; - $('[data-inline-panel-child-move-up]', this).prop('disabled', isFirst); - $('[data-inline-panel-child-move-down]', this).prop('disabled', isLast); + $('[data-inline-panel-child-move-up]:first', this).prop( + 'disabled', + isFirst, + ); + $('[data-inline-panel-child-move-down]:first', this).prop( + 'disabled', + isLast, + ); }); } } diff --git a/docs/releases/6.1.md b/docs/releases/6.1.md index f5a115bc97..7a008d5893 100644 --- a/docs/releases/6.1.md +++ b/docs/releases/6.1.md @@ -25,6 +25,7 @@ depth: 1 * Fix typo in `__str__` for MySQL search index (Jake Howard) * Ensure that unit tests correctly check for migrations in all core Wagtail apps (Matt Westcott) * Correctly handle `date` objects on `human_readable_date` template tag (Jhonatan Lopes) + * Ensure re-ordering buttons work correctly when using a nested InlinePanel (Adrien Hamraoui) ### Documentation