How can I retrieve the value of a PASTE (copy-pasta) event in a GWT TextBox?
- by dominicbri7
Hello fellow SO members,
I want to prevent the user from copy-pasting values in my TextBox IF AND ONLY IF the values do not respect a certain condition.
For instance, I created a DigitsOnlyTextBox which will be used for phone numbers.
I already made it so only Character.isDigit characters can be typed into the box, and the user cannot copy-paste values into it, using :
this.sinkEvents(Event.ONPASTE);
and
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
// Permet d'empêcher le copier-coller, donc d'entrer des caractères non-numériques
if (event.getTypeInt() == Event.ONPASTE) {
event.stopPropagation();
event.preventDefault();
}
}
But I'd like to verify if the copy-pasted String is "digits only" and if so, let the event happen (therefore the text added).
tl;dr :
see title
Thank you for your time.
Sincerely.