question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImageChooserField does not work in nested forms.

See original GitHub issue

After this feature we are able to create nested related objects in the same form. But when we use ImageChooserField at the second level or deeper - Wagtail shows regular select instead of ImageChooserField. On the screenshot, ImageChooserField is setted for the logo field.

screenshot from 2019-03-07 21-07-27

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
MaziyarMKcommented, Mar 31, 2020

Got SnippetChooserPanel working with this:

from wagtail.admin.edit_handlers import InlinePanel as BaseInlinePanel

class InlinePanel(BaseInlinePanel):
    def widget_overrides(self):
        widgets = {}
        child_edit_handler = self.get_child_edit_handler()
        for handler_class in child_edit_handler.children:
            widgets.update(handler_class.widget_overrides())
        widget_overrides = {self.relation_name: widgets}
        return widget_overrides

Basically the nested-second-layer InlinePanel wasn’t providing the Page model with any widgets, while the first layer InlinePanel was doing so. Haven’t tested it with different combinations (third layer, all layers having custom panels, etc).

nested inlinepanel

6reactions
bryliecommented, May 26, 2021

The suggestion above for creating a custom InlinePanel worked in my case, as such:

from wagtail.admin.edit_handlers import InlinePanel


class NestedInlinePanel(InlinePanel):
    def widget_overrides(self):
        widgets = {}

        child_edit_handler = self.get_child_edit_handler()

        for handler_class in child_edit_handler.children:
            widgets.update(handler_class.widget_overrides())

        widget_overrides = {self.relation_name: widgets}

        return widget_overrides

One thing of note is that the title and help_text don’t work with the custom NestedInlinePanel.

NestedInlinePanel(
    "authors",
    # Heading and help text are not rendered in the form UI
    heading="Authors",
    help_text="Select one or more authors who contributed to this article",
 ),
Read more comments on GitHub >

github_iconTop Results From Across the Web

Doesn't seem to work in Nested Forms - WordPress.org
Anyone else having this problem? maybe because I have a lot of Address fields, I get a console error with nested form field...
Read more >
Issues with nested forms - Stack Overflow
A few things to look at. first, this function: $('form').on('click', '.add_fields', function(event) { let regexp, time; time = new Date().
Read more >
Form Layout | Nested | JET Developer Cookbook - Oracle
A form layout manages the layout of labels and fields in a form. This shows nested forms. To see responsive behavior try one...
Read more >
Nested Forms in Rails - The Lean Software Boutique
Have you ever had to deal with complex forms creating multiple objects ... If you try that code as is, it won't work...
Read more >
Angular: Nested Reactive Forms Using ... - Medium
We have successfully integrated our nested child form control into our Angular Core. But there is still one problem. Even though our place...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found