Search code examples
javascripthandsontable

Is there a way to prevent pasting after checking the selection?


I am looking for a way to prevent the user from pasting depending on their copied selection and pasting selection (e.g. stop the user from pasting a column if they copied an entire row and vice versa).

I've looked into the beforePaste() method and other members related to the copyPaste plugin, but I can't find any way to stop the paste.

Ideally, I want the user's selected range to remain the same, but without any data being pasted.


Solution

  • beforePaste is not a method. It's a callback, or a hook in Handsontable nomenclature.

    If beforePaste hook returns false the action will not be executed. Try this:

    hot.addHook('beforePaste', function () {
      if (whatever) {
        return false;
      }
    });