From 96b5f45fad4936699a5ec50f0dfb008f1696f2aa Mon Sep 17 00:00:00 2001 From: elhussein almasri Date: Fri, 22 Dec 2023 22:17:15 +0000 Subject: [PATCH] display-character-count-to-RichTextBlock --- client/src/components/StreamField/blocks/FieldBlock.js | 4 ++++ client/src/entrypoints/admin/telepath/widgets.js | 5 +++++ wagtail/blocks/field_block.py | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/client/src/components/StreamField/blocks/FieldBlock.js b/client/src/components/StreamField/blocks/FieldBlock.js index 7f0a31db1c..75d3289eb6 100644 --- a/client/src/components/StreamField/blocks/FieldBlock.js +++ b/client/src/components/StreamField/blocks/FieldBlock.js @@ -155,6 +155,10 @@ export class FieldBlock { attributes.required = ''; } + if (this.blockDef.meta.maxLength) { + attributes.maxLength = this.blockDef.meta.maxLength; + } + return attributes; } diff --git a/client/src/entrypoints/admin/telepath/widgets.js b/client/src/entrypoints/admin/telepath/widgets.js index 33e442cfbd..79dc6891ff 100644 --- a/client/src/entrypoints/admin/telepath/widgets.js +++ b/client/src/entrypoints/admin/telepath/widgets.js @@ -378,6 +378,11 @@ class DraftailRichTextArea { input.id = id; input.name = name; + if (typeof options?.attributes === 'object') { + Object.entries(options.attributes).forEach(([key, value]) => { + input.setAttribute(key, value); + }); + } // If the initialState is an EditorState, rather than serialized rawContentState, it's // easier for us to initialize the widget blank and then setState to the correct state const initialiseBlank = !!initialState.getCurrentContent; diff --git a/wagtail/blocks/field_block.py b/wagtail/blocks/field_block.py index 876b14b34a..42f96629e5 100644 --- a/wagtail/blocks/field_block.py +++ b/wagtail/blocks/field_block.py @@ -120,6 +120,9 @@ class FieldBlockAdapter(Adapter): if block.field.help_text: meta["helpText"] = block.field.help_text + if hasattr(block, "max_length") and block.max_length is not None: + meta["maxLength"] = block.max_length + return [ block.name, block.field.widget, @@ -678,6 +681,7 @@ class RichTextBlock(FieldBlock): "help_text": help_text, "validators": validators, } + self.max_length = max_length self.editor = editor self.features = features self.search_index = search_index