Disable Drag and Drop

0 Answers 52 Views
Editor
shashank
Top achievements
Rank 1
Iron
shashank asked on 28 Aug 2023, 07:57 PM

I want to disable drag and drop images from local folders or copy paste the images from clipboard into the Kendo Editor (https://demos.telerik.com/aspnet-core/editor). 
I am using this function emailEditorPaste() to prevent such ,

function emailEditorPaste(e) { var clipboardData = e.event.clipboardData || window.clipboardData; var items = clipboardData.items; for (var i = 0; i < items.length; i++) { var item = items[i]; if (item.type.indexOf("image") !== -1) { e.preventDefault(); console.log("Images cannot be pasted here"); break; } } }

and I have appended it to the Paste events on Editor as in here
@(Html.Kendo().EditorFor(m => m.MsgT.body) . .Tools(tools => tools .Clear() .FontName().FontSize() .Bold().Italic().Underline() .JustifyLeft().JustifyCenter().JustifyRight() .ForeColor().BackColor() .InsertUnorderedList().InsertOrderedList() .Outdent().Indent() .CreateLink().Unlink() .InsertImage() ) .Events(events => events .Change("emailEditorChange") .Paste("emailEditorPaste")

emailEditorPaste() works fine in not allowing me the user to drag and drop the images but when I have a text copied to clipboard and I try to paste it into editor , it doesn't paste on first attempt and throws a console error:
"Cannot read properties of undefined (reading 'clipboardData')
TypeError: Cannot read properties of undefined (reading 'clipboardData')" .

On second attempt the text is pasted into the editor just fine.

I looked all places but I am still missing something, can you please share me some resources on how to disable the drag and drop images into the editor.

shashank
Top achievements
Rank 1
Iron
commented on 29 Aug 2023, 04:12 PM

issue resolved

No answers yet. Maybe you can help?

Tags
Editor
Asked by
shashank
Top achievements
Rank 1
Iron
Share this question
or