Problem/Motivation

When using CKEditor 5 with MaxLength the character count stops when the text format is changed to another format that is using a CKEditor.

Steps to reproduce

Add a MaxLength to a Text (formatted,long) field

After the page loads, on that text field change the Text format to another CKEditor 5 format.

Enter in text and you'll see the character content not update

Proposed resolution

Workaround

After changing the text format, save the form. Return to edit the form and MaxLength will begin working again for the new format.

Remaining tasks

  • ❌ Get maintainer approval for the proposed resolution
  • ❌ Implement resolution
  • ❌ Write test coverage (contact a maintainer if you need help)
  • ❌ Maintainer review via the UI
  • ❌ Maintainer Code Review #1
  • ❌ Maintainer code review #2
  • ❌ Merge into dev branch, with credit to author and participants

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
maxlength-count-not-updating.png65.99 KBacemichael

Issue fork maxlength-3391779

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

acemichael created an issue. See original summary.

ravi kant’s picture

The issue is in Full HTML of ckeditor-5.

cedewey’s picture

Version: 2.1.2 » 3.x-dev
Issue summary: View changes

Thanks for reporting this issue acemichael,

I can reproduce this issue as well.

A workaround is to save the form, edit it again and the MaxLength functionality begins working again.

I'm going to update this to be a 3.x-dev issue since that is the new version we will be actively maintaining.

cedewey’s picture

Title: CKEditor5 - character count stops » CKEditor5 - character count stops when the text format is changed

godotislate made their first commit to this issue’s fork.

godotislate’s picture

Status: Active » Needs review

I put in an MR for a change that worked for me:
Testing steps:
1. Installed Drupal core with standard profile (10.3.x)
2. Installed MaxLength 3.0.0-beta1
3. Configured article content type's body field widget to have a maxlength
4. Created a new article node
5. Typed some text into body field (format initially Basic HTML) and confirmed counter matches typing
6. Switched formats to Full HTML and confirmed via dialog
7. Resumed typing and confirmed counter still matches characters typed.

The fix is slightly ugly with the use of the MutationObserver. I think it can be cleaned up once #3319358: Trigger event when Text Editor is attached in Drupal core is in, and there's event that can be listened for instead.

Going to put in needs review for feedback, though it probably needs tests.

joevagyok’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thank you for the contribution! Would be nice to see a test for this without the solution to validate the issue and in a new commit adding the fix should make the test pass.

godotislate’s picture

Status: Needs work » Needs review
joevagyok’s picture

Assigned: Unassigned » joevagyok
chewie’s picture

Status: Needs review » Reviewed & tested by the community

Fix looks good.

joevagyok’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.