Editor - onclick event is stripped from content

1 Answer 72 Views
Editor
James
Top achievements
Rank 1
James asked on 28 Sep 2023, 07:48 AM | edited on 28 Sep 2023, 07:48 AM

I have some content that consists of an image with a hidden link. (It used to be a button, but I found that the button was being stripped out entirely. If there's a way to fix this, I will probably go back to the button.)

<div class="divbutton">
<p>
<img src="data:image/jpeg;base64,foo" alt="Xsctn_Strat-Struct.jpeg" title="Xsctn_Strat-Struct.jpeg" style="width: 100px" class="Figure-Preview" id="64319096-9a51-418d-a11b-e70d25d9cb0e" contenteditable="false" draggable="true">
<a contenteditable="false" onclick="parent.image_preview(document.getElementById('64319096-9a51-418d-a11b-e70d25d9cb0e').src)">EXPAND</a>
</p>
</div>

When I inspect the <a> element, it's missing its onclick (and contenteditable attribute, although that is not critical.)

If I manually recreate the onclick event in the DevTools, it works perfectly.

How can I stop it from being removed?

1 Answer, 1 is accepted

Sort by
1
Accepted
Konstantin Dikov
Telerik team
answered on 29 Sep 2023, 08:38 AM

Hello James,

The Editor nodes have predefined set of supported attributes and for introducing different attributes you will have to manually add them by updating the schema. I have created a simple example that adds support for preserving the "onclick":

More information on this matter can be found in the following help article:

Hope this helps.

 

Regards,
Konstantin Dikov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources!

James
Top achievements
Rank 1
commented on 05 Oct 2023, 12:43 AM

Thanks very much! I will follow this example.
James
Top achievements
Rank 1
commented on 27 Oct 2023, 07:45 AM

Sorry for the late follow-up, I have tried to follow your example but as far as I can tell the onclick is still being stripped from the Editor.

My fork: https://react-t8va7x-zpqmam.stackblitz.io

Konstantin Dikov
Telerik team
commented on 30 Oct 2023, 01:20 PM

Hi James,

The issue with the example that you have shared is with the escaping of the quotes. You should either escape them within the string as suggested in the following block post or use "&quot;":

Here is the correct syntax for the default content (and the modified example: https://stackblitz.com/edit/react-t8va7x-hrbbdm?file=app%2Fmain.tsx):

 defaultContent={
          '<h1>This is a Heading</h1><p>This is a paragraph.</p><p onclick=\'alert("447805d1-0d6e-48c7-ad83-22aef921e6dd")\'>EXPAND</p>'
        }

Tags
Editor
Asked by
James
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or