primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Primeng KeyFilter does not working well when user do Cut, Copy and Paste

Open lavchauhan opened this issue 8 years ago • 6 comments

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

lavchauhan avatar May 17 '18 10:05 lavchauhan

Any plan on the above issue in upcoming releases .

comlabmohan avatar Jul 06 '18 11:07 comlabmohan

Yes, I am also facing this issue. Kindly fix it in next release.

ghost avatar Sep 13 '18 10:09 ghost

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.

steigerm avatar Dec 31 '18 15:12 steigerm

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 avatar Jun 13 '19 15:06 cristianoquadros

@cristianoquadros Thanks for the solution but if you have to implement this in multiple forms then how would you do that like generic?

shinde-prasad avatar Aug 05 '19 08:08 shinde-prasad

@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.

ateffahi avatar Jun 19 '20 20:06 ateffahi