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

Commenting not working on pages with read_only FieldPanels #11838

Open
mattibo opened this issue Apr 11, 2024 · 2 comments
Open

Commenting not working on pages with read_only FieldPanels #11838

mattibo opened this issue Apr 11, 2024 · 2 comments

Comments

@mattibo
Copy link

mattibo commented Apr 11, 2024

Issue Summary

When editing pages with read_only FieldPanels commenting does not work on the whole page.

  • No Toggle button is visible
image
  • Error is show in the browser
image

I guess this is the specific line:

if (fieldNode.closest('[data-contentpath-disabled]')) {

At the execution the fieldNode is null.

Steps to Reproduce

For me it can be reproduced in a Page model with following content_panels:

content_panels = [FieldPanel("title", read_only=True, classname="title")]

Technical details

  • Python version: Python 3.11.1
  • Django version: Django==5.0.4
  • Wagtail version: wagtail==6.0.2
  • Browser version: Edge 123
@mattibo mattibo added status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug labels Apr 11, 2024
@mattibo
Copy link
Author

mattibo commented Apr 11, 2024

After a litte bit of investigation:

A read only FieldPanel has no field key inside the context:

def get_read_only_context_data(self):
# Define context data for BoundPanel AND read-only output rendering
context = {
"id_for_label": self.id_for_label(),
"help_text_id": "%s-helptext" % self.prefix,
"help_text": self.help_text,
"show_add_comment_button": self.comments_enabled,
"raw_value": self.value_from_instance,
"display_value": self.panel.format_value_for_display(
self.value_from_instance
),
}

The variable contentpath from the formattedfield tag is empty:

"contentpath": field.name if field else "",

Therefore the tag data-contentpath is not filled:

<div class="w-field {{ field_classname }}{% if has_errors %} w-field--error{% endif %}{% if show_add_comment_button %} w-field--commentable{% endif %}" data-field{% if contentpath %} data-contentpath="{{ contentpath }}"{% endif %}>

The FieldLevelCommentWidget wants to build a fieldNode and expects a data-contentpath:

function initAddCommentButton(buttonElement) {
const widget = new FieldLevelCommentWidget({
fieldNode: buttonElement.closest('[data-contentpath]'),
commentAdditionNode: buttonElement,
});
widget.register();
}

As a consequence, the fieldNode is null which leads to the error inside the browser from the screenshot above and no commenting is possible.

@rohitsrma
Copy link
Contributor

I can confirm that the issue exists.

When I set read_only=True for any field, I'm not getting option to add comments to any other fields. Also, an error shows up in the console.

Screenshot (59)

After doing some research, I mostly agree with what @mattibo mentioned above. When I changed the context's content_path to "contentpath": field.name if field else "disabled", the problem was fixed. But, I don't think hardcoding a value is the right way to solve this. So, I'm pretty sure the issue comes from the empty string we're using in the else condition. And, it's likely that one of these parts of the comments.js file is causing the problem.

if (fieldNode.closest('[data-contentpath-disabled]')) {

fieldNode: buttonElement.closest('[data-contentpath]'),

@lb-, I'm trying to find out the exact issue, but it would be really helpful if you could take a look too.

@lb- lb- added component:Commenting and removed status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. labels Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants