Primeng KeyFilter does not working well when user do Cut, Copy and Paste
Primeng KeyFilter does not working well when user do Cut, Copy and Paste.
Current behavior After Applying pKeyFilter="pint" on input textbox still user can able to input alphbetics using this keys Cut or Copy and Paste / (CTRL + X or CTRL) + C and CTRL + V
Expected behavior It should not be paste here when we have added pKeyFilter="pint" in input tags.
My environment:
-
Angular version: 5.2.6
-
PrimeNG version: 5.2.0
-
Browser: Chrome, Mozila Firefox, Safari, Internet Explorer 9,10,11
-
Language: TypeScript:2.4.2
-
Node (for AoT issues): 6.11.0
Any plan on the above issue in upcoming releases .
Yes, I am also facing this issue. Kindly fix it in next release.
Was this fix tested with IE? I have implemented similar functionality before and had to use
let input: string;
if (typeof event.clipboardData === 'undefined') {
//Internet Explorer
input = (<any>window).clipboardData.getData('Text');
} else {
//all other browsers
input = event.clipboardData.getData('Text');
}
before testing the regex.
I have been some problem with pint mode. I really need to use paste in inputtext. So, my solution was change this part of the code:
@HostListener('paste', ['$event'])
onPaste(e) {
const clipboardData = e.clipboardData || (<any>window).clipboardData;
if (clipboardData) {
const pastedText = clipboardData.getData('text');
if (!this.regex.test(pastedText)) {
e.preventDefault();
}
}
}
@cristianoquadros Thanks for the solution but if you have to implement this in multiple forms then how would you do that like generic?
@cagataycivici
could you correct onPaste(e) for IE 11 please like that :
public onPaste(e) : void {
const clipboardData = e.clipboardData || (window as any).clipboardData;
if (clipboardData) {
const pastedText = clipboardData.getData('text');
for (let char of pastedText.toString()) {
if (!this.regex.test(char)) {
e.preventDefault();
return;
}
}
}
}
thanks to @cristianoquadros.