Tagify: Force paste as plain text

Created on 21 Dec 2019  路  4Comments  路  Source: yairEO/tagify

I noticed that Tagify does some odd things when you try to paste formatted/rich text into it. Here is one possible solution:
http://jsfiddle.net/HBEzc/

Could something like this be implemented?

Suggestion

Most helpful comment

newlines (\n or \r\n) should remain intact. I have some idea I want to try.

I am aware of this problem

All 4 comments

newlines (\n or \r\n) should remain intact. I have some idea I want to try.

I am aware of this problem

It would be great if pasting rich text would work 馃憤 or if there's a simple solution for adding it.
Update: Actually, i tried the snippet of the example that @thetuningspoon posted in combination with a paste event on the Tagify input and it worked 馃槉

Is there any plan to support pasting markup / rich text? This makes tagify unusable when pasting any content from google spreadsheets, for example. Any thoughts?

Well I added easily copy as text to Tagify after it's creation but something like this might be better added to the core @yairEO

   var TAGIFY = new Tagify(input, {
      ....
    })

    //Add events
    function handlePaste (e) {
      var clipboardData, pastedData;

      // Get pasted data via clipboard API
      clipboardData = e.clipboardData || window.clipboardData;
      pastedData = clipboardData.getData('Text');

      // insert text manually
      document.execCommand("insertHTML", false, pastedData);

      // Stop data actually being pasted into div
      e.stopPropagation();
      e.preventDefault();
    }

    function handleCopy (e) {
      const selection = document.getSelection();
      var copyText = selection.toString();

      event.clipboardData.setData('text/plain', copyText);

      // Stop the default copy
      e.stopPropagation();
      e.preventDefault();
    }

    TAGIFY.DOM.input.addEventListener('paste', handlePaste);
    TAGIFY.DOM.input.addEventListener('copy', handleCopy);
Was this page helpful?
0 / 5 - 0 ratings