-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
RichTextField not visible when used as a field on custom Image model #4466
Comments
Hey @eyemyth, could you:
|
@thibaudcolas I do get errors in the console, and they seem to correlate directly to the form field, which does appear in the HTML. HTML: <input type="hidden" name="caption" value="{
"blocks": [
{
"key": "ugovi",
"type": "unstyled",
"depth": 0,
"text": "",
"inlineStyleRanges": [],
"entityRanges": []
}
],
"entityMap": {}
}" id="id_caption" data-draftail-input /><script>window.draftail.initEditor('#id_caption', {"entityTypes": [{"type": "EMBED", "icon": "media", "description": "Embed"}, {"type": "LINK", "icon": "link", "description": "Link", "attributes": ["url", "id", "parentId"], "whitelist": {"href": "^(http:|https:|undefined$)"}}, {"type": "DOCUMENT", "icon": "doc-full", "description": "Document"}, {"type": "IMAGE", "icon": "image", "description": "Image", "attributes": ["id", "src", "alt", "format"], "whitelist": {"id": true}}], "enableHorizontalRule": true, "inlineStyles": [{"type": "BOLD", "icon": "bold", "description": "Bold"}, {"type": "ITALIC", "icon": "italic", "description": "Italic"}], "blockTypes": [{"label": "H2", "type": "header-two", "description": "Heading 2"}, {"label": "H3", "type": "header-three", "description": "Heading 3"}, {"label": "H4", "type": "header-four", "description": "Heading 4"}, {"type": "ordered-list-item", "icon": "list-ol", "description": "Numbered list"}, {"type": "unordered-list-item", "icon": "list-ul", "description": "Bulleted list"}]}, document.currentScript)</script> The error I see in the console is Here is my Image model: class InlineImage(AbstractImage):
title = models.CharField(max_length=200, blank=True)
caption = RichTextField(blank=True)
credit = RichTextField(blank=True)
legacy_page_id = models.PositiveSmallIntegerField(
null=True,
default=None,
)
legacy_order = models.PositiveSmallIntegerField(
null=True,
default=None,
)
admin_form_fields = Image.admin_form_fields + (
'caption', 'credit',
) |
@eyemyth 👍 this looks like a cache issue but would you mind copying the full log so I can confirm? |
The actual error as printed in the Safari console is:
|
I get the same error when the editor's code isn't loaded on the page. There are two things that I think might cause this:
Once you've tried clearing browser / static file caches, have a look at the HTML source for your page and make sure it contains If the |
Hm, yeah that Here's the complete HTML output from the Safari Resources tab: https://gist.github.com/eyemyth/685344a45652ff871ce0047712f87d72 |
Ok, the problem is easier to understand now. This page template (https://github.com/wagtail/wagtail/blob/master/wagtail/images/templates/wagtailimages/images/edit.html) does not load the required JS and CSS for the widgets rendered there, nor any of the other requirements for rich text editor fields in Wagtail. A quick fix might be to override this template's Let's way to hear from others who may be more knowledgeable about image overrides. In the meantime, if possible I would suggest you use a field that does not need any extra JS or CSS instead. |
I managed to get the fields to render on the page, although oddly they do not have the field names listed. Here's a screenshot. I overrode the edit.html template and added I would be nice to have native/out of the box RichTextField functionality here. Our editors will want to have some basic text formatting tools for image captions. |
I think the 'proper' fix for this will be to ensure that the edit form's media property is output onto the page - this should include the necessary draftail.css and draftail.js includes. (However, it may still be lacking some of the additional includes normally found in Note that having a rich text field within the image model could also cause problems with the 'upload' tab of the image chooser popup, because the rich text field may itself trigger popups, and a popup within a popup isn't officially supported... |
I have the same problem, but with custom Document model, and it seems that #5286 has fixes only for Image model, so should it be fixed for Document separately? |
@sir-sigurd Yes - a similar fix for custom document models would be very welcome, and will probably look a lot like this one. (As I recall, I considered fixing documents at the same time as doing this, but eventually decided it was best not to get carried away doing too much in one PR :-) ) |
@gasman, OK, I’ll probably have time to fix it. |
If anyone else is looking for an answer to this question, I’ve fixed it by implementing the fix from here:
Essentially, the old implementation should be replaced with this:
|
Issue Summary
RichTextField fields are not visible in the CMS when used as a field on custom Image model.
Steps to Reproduce
I set up a custom image model as described here. I added a
wagtail.core.fields.RichTextField
as one of the fields, and added that field name toadmin_form_fields
. I expected the field to appear at /cms/images/{pk} but it does not. Other standard-issue Django fields added in the same way do appear in the CMS.Technical details
The text was updated successfully, but these errors were encountered: