Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: paste event on htmleditor extjs 5

  1. #1

    Default paste event on htmleditor extjs 5

    what is the best way to bind a listener for paste event for a html editor?
    I have something set up in the initiliaze function that doesn seem to be get triggered. I also see that eventmanager has been deprecated in this new release. I want to find out the right way to get this done.
    here is a snippet :

    initialize: function(editor) {


    Ext.EventManager.on(this.editor.getDoc(), {
    'paste': function(){

    Ext.EventManager.stopEvent("change");
    me.processNoteText(false);
    },
    buffer: 200,
    scope: this
    });

    },
    tia!!

  2. #2
    Sencha - Sustaining Engineer tristan.lee's Avatar
    Join Date
    Mar 2015
    Location
    Central Ohio
    Posts
    1,579
    Answers
    165

    Default

    Hi,

    It does not look like this functionality is directly supported unfortunately. I did get this to work by setting the onpaste function directly on the editor body. Note, though, that getEditorBody() is a private method. It's undocumented and could be changed/removed in future releases.



    Hope this helps,
    Tristan

  3. #3

    Default

    the use case for pasting into a html editor seems common enough.. could we maybe consider adding this to the component itself. using a private method seems unsafe to me

  4. #4

    Default

    also what's the best way to get this pasted content? editor.getValue is empty in the onpaste handler

  5. #5
    Sencha - Sustaining Engineer tristan.lee's Avatar
    Join Date
    Mar 2015
    Location
    Central Ohio
    Posts
    1,579
    Answers
    165

    Default

    The paste event seems to be fired before the content is available from the editor. To get reference to is within onpaste, you could invoke a function at the end of the event queue so that the value is available.



    I also agree that having this functionality inherit to the editor publicly would be very helpful. I've added this as a feature request for consideration for future versions.

    Thanks,
    Tristan

  6. #6
    Sencha Premium User
    Join Date
    Feb 2011
    Location
    NJ
    Posts
    337
    Answers
    62

    Default

    You can access the paste data from the event:

    Code:
    editor.getEditorBody().onpaste = function (event) {
        console.log(event.clipboardData.getData('text'));
    };

  7. #7
    Sencha - Sustaining Engineer tristan.lee's Avatar
    Join Date
    Mar 2015
    Location
    Central Ohio
    Posts
    1,579
    Answers
    165

    Default

    I've updated my fiddle to include your solution for the original data (vs the rich version of the editor). However, I could not get any details from the clipboard.

  8. #8

    Default

    I have managed to get this going. but I have another related question. what is the best way to strip out all html tags other than anchor tags ?

  9. #9
    Sencha - Sustaining Engineer tristan.lee's Avatar
    Join Date
    Mar 2015
    Location
    Central Ohio
    Posts
    1,579
    Answers
    165

    Default

    If you want to handle this via JS, you can use a regular expression:

    http://regexr.com/3au8c


  10. #10
    Sencha User
    Join Date
    Feb 2015
    Location
    Russia
    Posts
    9

    Default

    Quote Originally Posted by droessner View Post
    You can access the paste data from the event:

    Code:
    editor.getEditorBody().onpaste = function (event) {
        console.log(event.clipboardData.getData('text'));
    };
    doesn't work for chrome 46. It's loging an empty string

Page 1 of 2 12 LastLast

Similar Threads

  1. HtmlEditor & raw text paste
    By Araberen in forum Ext: Q&A
    Replies: 1
    Last Post: 29 Nov 2011, 7:00 AM
  2. copy&paste between Two htmleditor
    By ragecf in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 4 Sep 2011, 4:12 AM
  3. Paste values from Excel paste buffer into Extjs Grid?
    By jimm in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 11 Mar 2011, 3:40 PM
  4. paste event on htmlEditor
    By fred_p in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 5 Aug 2008, 5:08 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •