Problem/Motivation

So my project has a few custom ckeditor plugins which add some custom HTML into the editor (which all needed to be rewritten for them to work with ckeditor5). I have these working for the most part...however I am seeing an issue when placing in a custom button into the editor.

The way I have these plugins set up is if they are double clicked, a modal opens up with a form where I can edit its attributes:
ckeditor5 modal

So this example will place an html button into the editor with html that looks like this (when viewing the source):
<button class="align-right" data-href="/node/1" data-text="click me" data-align="align-right">click me</button>

The code when inspecting the button in the editor itself looks like this:
<button class="align-right ck-editor__editable ck-editor__nested-editable" role="textbox" contenteditable="true">click me</button>

When I double click the button in the editor it to edit its attributes again, Drupal thinks I am submitting the node add form itself. The modal does open for a split second, but disappears when the page refreshes. I have a few other custom plugins that work similar to this, but those work fine.

I'm not sure why this is happening...but I think it has something to do with the fact that the contents of the ckeditor4 are inside of an iframe, whereas ckeditor5 it is not. I can't modify the HTML in any way as buttons placed previously using ckeditor4 need to continue to work.

Proposed resolution

Make sure an html button click does not attempt to submit the node add/edit form.

CommentFileSizeAuthor
ckeditor5-modal.png15.7 KBtlo405

Comments

tlo405 created an issue. See original summary.

tlo405’s picture

Title: Clicking an HTML button inside the editor attempts to submit the node add form » Clicking an HTML button inside the editor attempts to submit the node add/edit form
cilefen’s picture

Issue tags: -ckeditor5, -node add/edit form +Needs steps to reproduce

This is filed as a bug report. I suppose we would need steps to reproduce it, which I think include having your custom code. Otherwise it should be a support request. Also: Drupal 9.4.x is no longer to be released except for security bug fixes.

wim leers’s picture

Category: Bug report » Support request
Issue tags: -Needs steps to reproduce

That's not "Drupal" that thinks this — nor CKEditor 5; it's your browser.

So my project has a few custom ckeditor plugins […]

It's the responsibility of these plugins to ensure that the default behavior is prevented (event.preventDefault()) when interacting with the HTML you generate!

wim leers’s picture

Title: Clicking an HTML button inside the editor attempts to submit the node add/edit form » Custom CKEditor 5 plugin: clicking an HTML button inside the editor attempts to submit the node add/edit form
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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