0

When working through the example of setting up a "Mark" button for the draftail as per the instructions on https://docs.wagtail.org/en/stable/extending/extending_draftail.html I find it does not work for Wagtail 4.1.1. This is like the simplest getting started example I can find. I followed the steps by creating a wagtail_hooks.py file in a new app folder and no button appears in the rich text editor nor along the side?

This is all I have in models.py

from django.db import models

from wagtail.models import Page
from wagtail.fields import RichTextField
from wagtail.admin.panels import FieldPanel


class HomePage(Page):
    body = RichTextField(null=True, blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('body'),
    ]

that and the wagtail_hooks.py lifted straight from the documentation. Any ideas on why this isn't working?

Kiwiheretic
  • 308
  • 2
  • 12

1 Answers1

0

You need to add mark to the feature list on your RichTextBlock. At the moment, without any feature declaration, it just loads the default features.

Maybe something like

body = RichTextField(null=True, blank=True, features= ['bold', 'italic', 'link', 'mark'])

Or whichever features you want to use.

I'd recommend adding the WAGTAILADMIN_RICH_TEXT_EDITORS settings to your base.py so you don't need to declare the full list each time. For example:

WAGTAILADMIN_RICH_TEXT_EDITORS = {
    'default': {
        'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea',
        'OPTIONS': {
            'features': ['h2', 'h3', 'h4', 'bold', 'italic', 'link', 'ol', 'ul', 'hr']
        }
    },
    'full': {
        'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea',
        'OPTIONS': {
            'features': ['h2', 'h3', 'h4', 'h5', 'h6', 'bold', 'italic', 'ol', 'ul',
                         'link', 'hr', 'code', 'document-link', 'blockquote']
        }
    },
    'minimal': {
        'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea',
        'OPTIONS': {
            'features': ['bold', 'italic', 'link']
        }
    },
}

Then you can call RichTextBlock(editor='minimal') for the minimal feature set etc..

I found the draftail documentation really hard to work through. It skips a lot of vital info, and skims over others, giving code examples without any explanation.

Maybe these articles help explain a bit more

  • Why do I have to explicitly list it in the feature list of the field when the documentation says the following? ``` # 6. (optional) Add the feature to the default features list to make it available # on rich text fields that do not specify an explicit 'features' list features.default_features.append('mark') ``` – Kiwiheretic Dec 02 '22 at 00:27
  • Good question - that line has never worked for me either. The Learn Wagtail video series uses the same code and also manually adds it to the feature list. There's a lot in the draftail documentation that make little sense. The entity section is a nightmare. The dratail website doesn't help either. – Rich - enzedonline Dec 02 '22 at 09:03