# preventDefault does not work in onPaste

**URL:** <https://discuss.codemirror.net/t/preventdefault-does-not-work-in-onpaste/563>\
**Category:** Uncategorized\
**Created:** [December 11, 2015, 5:28am UTC](https://discuss.codemirror.net/t/preventdefault-does-not-work-in-onpaste/563 "2015-12-11T05:28:51Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![barelyfitz](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/barelyfitz/32/215_2.png) [@barelyfitz](https://discuss.codemirror.net/u/barelyfitz)\
**Post date:** [December 19, 2015, 1:27am UTC](https://discuss.codemirror.net/t/preventdefault-does-not-work-in-onpaste/563/4 "2015-12-19T01:27:16Z")

</div>

I had a similar problem - in an older version of CodeMirror, it was possible to cancel the paste event, but it appears that the paste functionality has been refactored and this no longer works.

I wouldn’t call undo(), that seems to be a lot of wasted processing if you do that. I would do as marijn suggested - set up a beforeChange listener and cancel the change if it is a paste.

---

_[View the full topic](https://discuss.codemirror.net/t/preventdefault-does-not-work-in-onpaste/563)._
