'How can I block copy-paste in a text field?
I'm using vaadin 22 and I want to block the copy-paste of an emailField to implement email confirmation. Can someone help me. Thank you
Solution 1:[1]
In HTML you want to archive something like this:
<input type="textbox" onpaste="return false;" oncopy="return false" oncut="return false" ondrag="return false" ondrop="return false">
Demo here: https://jsfiddle.net/f4g6opcm/1/
So you can simply add this Attributes via Vaadin like this:
TextField textfield = new Textfield();
textfield.getElement().setAttribute("onpaste", "return false");
textfield.getElement().setAttribute("oncopy", "return false");
textfield.getElement().setAttribute("oncut", "return false");
textfield.getElement().setAttribute("ondrag", "return false");
textfield.getElement().setAttribute("ondrop", "return false");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Oliver Stahl |
