0

I have an application that contains a large number of digit/Editors created declaratively. I need to add an onpaste event to these editors in order to convert the pasted content to plain text before pasting. I am having trouble getting the event to trigger. I have tried attaching the event both as a component in data-dojo-props and as a separate data-dojo-attach-event attribute. Neither seem to work.

Here is an example of one of the fields:

<div  data-dojo-type="dijit/Editor" id="Editor1" name="Editor1Content"  
data-dojo-props="extraPlugins:
['createLink','unlink','fontSize','foreColor','hiliteColor'], 
onChange:function(){MarkDocAsChanged();}" data-dojo-attach-
event="onPaste:function(){pasteAsPlainText(event);}" >This is the current 
field content</div>

Can anyone point me in the right direction?

Becca D
  • 13
  • 4
  • Did you forgot to add "dojox.editor.plugins.SafePaste" in your code? by default Editor doesn't have onPaste event. See here https://dojotoolkit.org/api/ – bajji May 29 '18 at 14:34
  • Are you saying that if I include the SafePaste plugin I will be able to use onpaste? Or do I need to somehow use the SafePaste plugin to call my function? – Becca D May 30 '18 at 11:41

2 Answers2

0

Looking at the dijit/Editor doc, it doesn't seem to have support for the onPaste event. You could try attaching an onpaste listener to the widget.domNode, intercept the event, and convert the value there and then set it as the widget.value.

  • Something like this does seem to be the only route. I was hoping to avoid it given how many editors there are in the application. – Becca D Jun 05 '18 at 10:48
0
// try to registe the paste event with "dojo/on" on the domNode
on(target, "paste", function(event){
              var textClipboard = "";
              if (typeof event.clipboardData !== "undefined") {// on Chrome & FF
                  textClipboard = event.clipboardData.getData("text/plain");
              } else if (typeof clipboardData !== "undefined") { // IE
                  textClipboard = clipboardData.getData("text");
              }
// use document.execCommand("insertText", false, text) or
// document.execCommand("paste", false, text) in IE to paste content
          });
Blz Abdos
  • 1
  • 3