Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front-end reordering issue of orderables in Wagtail 4.0 & 4.0.1 #9145

Closed
1 task
robertbrecevic opened this issue Sep 6, 2022 · 5 comments · Fixed by #9149
Closed
1 task

Front-end reordering issue of orderables in Wagtail 4.0 & 4.0.1 #9145

robertbrecevic opened this issue Sep 6, 2022 · 5 comments · Fixed by #9149

Comments

@robertbrecevic
Copy link

robertbrecevic commented Sep 6, 2022

Issue Summary

After upgrading to Wagtail > 4.0 the admin frontend stopped saving the push-up and push-down reordering of orderables referenced through an inline-panel. The UI responds correctly by moving the orderables up and down, but the state is neither saved once the post is published — nor is the changing of the sort order reflected in the live preview.

Steps to Reproduce

  1. In order to rule out failing dependencies I started a completely new project with wagtail start myproject and made a test.
  2. I edited the models.py in the default home app as follows and added two classes: a model and a orderable.
class CollectionPage(Page):
    content_panels = Page.content_panels + [
        InlinePanel(
            'collection_item', 
            heading="My collection", 
            label='collection item'
        ),
    ]


class CollectionItem(Orderable):
    page = ParentalKey(
        'home.CollectionPage', 
        related_name='collection_item'
    )
    my_image = models.ForeignKey(
        "wagtailimages.Image",
        null=True,
        blank=False,
        on_delete=models.SET_NULL,
        related_name="+",
    )
    panels = [FieldPanel("my_image")]

The result is the following: In the admin panel I am able to create new collection pages and choose collection items that consist of Wagtail images. Once I have established the parentally-relations they are not reorderable. The move up and down in UI and when I publish the post, the changes in order are not saved. Neither are the changes reflected in the live preview panel.

  1. I consider this to be a bug, since the orderables have been working exemplary all the way up to the latest updates of Wagtail. If I change the sort order directly in the database, this is indeed reflected in the frontend. The issue appears to be related to the UI-functionality in the page-editor.js (or related bindings. The UI-state is not registered outside its internal interface relationships.
  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: (yes / no)

Yes!

Technical details

  • Python version: Python 3.10.0
  • Django version: Django 4.1.1
  • Wagtail version: Wagtail 4.0.1
  • Browser version: Safari 15 & Chrome 105

Follow up

@robertbrecevic robertbrecevic added status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug labels Sep 6, 2022
@gasman gasman added this to the 4.0.2 milestone Sep 6, 2022
@lb-
Copy link
Member

lb- commented Sep 6, 2022

Can confirm this issue exists, the order input value is not being updated.

Screen Shot 2022-09-06 at 8 14 42 pm

Screen Shot 2022-09-06 at 8 15 01 pm

See above - re-ordering does not change the input value & then after saving, then loading the page again, the items go back to the original order.

Screen Shot 2022-09-06 at 8 15 23 pm

@lb- lb- added component:Frontend component:Panels component:Model Cluster and removed status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. labels Sep 6, 2022
@lb-
Copy link
Member

lb- commented Sep 6, 2022

The issue is the use of https://api.jquery.com/children/ no longer working with the new DOM structure introduced by #8983 / ca7f23d

However, the fix may need to be carefully done as to not break nested inline panels.

      $up.on('click', () => {
        const currentChildOrderElem = currentChild.children(
          'input[name$="-ORDER"]',
        );

What is happening here is it is finding the ORDER input element as a direct child of the panel, but these inputs are now one node down inside the w-panel__content not the w-panel.

Maybe we can move the inputs up? update - this will not work due to the panel component usage.
Maybe we can look for the next children only?

We should really pull this code out to its own file and add unit tests for this code as it is quite fragile.

lb- added a commit to lb-/wagtail that referenced this issue Sep 6, 2022
- fixes wagtail#9145
- no longer working with the new DOM structure introduced by wagtail#8983  / ca7f23d
- instead of using `$.children` use `$.find` to find the panel's input fields but ensure we still supported nested fields by finding based on the child panel's id
@lb- lb- mentioned this issue Sep 6, 2022
3 tasks
lb- added a commit to lb-/wagtail that referenced this issue Sep 6, 2022
- fixes wagtail#9145
- no longer working with the new DOM structure introduced by wagtail#8983  / ca7f23d
- instead of using `$.children` use `$.find` to find the panel's input fields but ensure we still supported nested fields by finding based on the child panel's id
@gasman gasman closed this as completed in 4b521c5 Sep 6, 2022
gasman pushed a commit that referenced this issue Sep 6, 2022
- fixes #9145
- no longer working with the new DOM structure introduced by #8983  / ca7f23d
- instead of using `$.children` use `$.find` to find the panel's input fields but ensure we still supported nested fields by finding based on the child panel's id
@enzedonline
Copy link

I still have this issue in 4.1.2 ... basic inline model:

class CarouselImages(Orderable):
    """Between 1 and 5 images for the home page carousel."""

    page = ParentalKey("blog.BlogPage", related_name="carousel_images")
    carousel_image = models.ForeignKey(
        "wagtailimages.Image",
        null=True,
        blank=False,
        on_delete=models.SET_NULL,
        related_name="+",
        verbose_name="Image"
    )
    caption = RichTextField(null=True, blank=True)

    panels = [FieldPanel("carousel_image"), FieldPanel("caption")]

    class Meta:
        verbose_name = 'Carousel Image'
    content_panels = Page.content_panels + [
        MultiFieldPanel(
            [InlinePanel("carousel_images", max_num=5, min_num=1)],
            heading="Carousel Images",
        ),

@gasman
Copy link
Collaborator

gasman commented Feb 19, 2023

@enzedonline Your class Meta: line needs to be class Meta(Orderable.Meta): - otherwise the presence of that meta class overwrites the ordering.

@enzedonline
Copy link

@gasman ha, thanks ... I'm wondering how I haven't come across that before now ... ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants