wagtail: Wagtail InlinePanel subpanels don't honor "collapsible collapsed"
Issue Summary
When overriding the wagtail.admin.panels.InlinePanel class’s child_edit_handler property; the returned MultiFieldPanel does not honor the collapsed class in the templates. I’d like to be able to individually collapse the subpanels of the InlinePanel; this provides a better overview while not taking up too much screenspace.
Steps to Reproduce
- Override the panel class like so:
class InlineOfficeHoursPanel(InlinePanel):
def __init__(self, *args, **kwargs):
kwargs["min_num"] = 7
kwargs["max_num"] = 7
super().__init__(*args, **kwargs)
@cached_property
def child_edit_handler(self):
panels = self.panel_definitions
child_edit_handler = MultiFieldPanel(panels, heading=self.heading, classname="collapsible collapsed")
return child_edit_handler.bind_to_model(self.db_field.related_model)
class BoundPanel(InlinePanel.BoundPanel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for index, child in enumerate(self.children):
child: MultiFieldPanel.BoundPanel
print(child.classname) # does print "collapsible collapsed".
....
- Define the panel on any model with a relationship suited for InlinePanel.
- Go to the wagtailadmin settings section, click on the office menu item and look at the panel.
Edit
Other, but might be same issue:
Panels from other models won’t collapse inside the inline panel either:
panels = [
MultiFieldPanel([
FieldPanel("day"),
FieldPanel("closed"),
], classname="collapsible collapse"), # not working
]
Would presumably be able to close this panel, but this is not the case. https://github.com/wagtail/wagtail/issues/11130#issuecomment-1783445118
Expected result:
Actual results:
Any other relevant information.
Though this might not be the conventional way of customising wagtail; it is and remains a Panel. The expectation would be for this to work. Though I don’t know how complex logic for this would be; I suspect it would be just as easy as with the heading attribute.
Going through the components/InlinePanel.ts makes me think more attributes are not supported; but I don’t know Typescript all too well; and don’t understand the intricacies of how panels are set up all too well.
- I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes
Technical details
- Wagtail version: 5.1.3, 5.2
About this issue
- Original URL
- State: open
- Created 8 months ago
- Reactions: 1
- Comments: 15 (9 by maintainers)
@Temidayo32 adding the
collapsible collapsedclasses translates to “this element should be collapsible, and it should be collapsed (that is closed) when the page loads”. So the issue is that they are not collapsed when you load the page, but they are collapsible manually as you have demonstrated@zerolab Thanks for the clarification. @Nigel2392 now, I see what the problem is.
Here’s my full code snippet, save you some time.
(imports might be duplicated; i like to split my models into separate files.)
@Nigel2392 let me try to reproduce this