wilson ramos
wilson ramos

Reputation: 31

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

Upvotes: 2

Views: 448

Answers (1)

Oliver Stahl
Oliver Stahl

Reputation: 644

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");

Upvotes: 4

Related Questions