Primefaces extension keyfilter doesn't allow to paste values

Community Driven Extensions Project
Post Reply
anatoly314
Posts: 34
Joined: 12 Feb 2014, 17:03

25 Aug 2014, 09:38

I'm using keyfilter from Primefaces extensions library, <pe:keyfilter/>. I use it together with regular expression which permits only numbers to be input. Everything works fine except that I can't paste a value into a field even if it fulfills regex. I mean I can't perform ctrl+v or right click -> paste with the mouse.

Is there workaround of this issue?

Or should I just use another validation method?
I use Primefaces 5.1 with Apache MyFaces 2.0.2 and Websphere 8.0.0.9

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

25 Aug 2014, 10:46

Set preventPaste to false.

But, e.g. if you only allow numbers and paste a text, it won't be removed. It's just a keyfilter, no mask.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

anatoly314
Posts: 34
Joined: 12 Feb 2014, 17:03

19 Oct 2014, 07:58

Thank you, I added also back-end validation to overcome this issue.
I use Primefaces 5.1 with Apache MyFaces 2.0.2 and Websphere 8.0.0.9

nandish
Posts: 7
Joined: 30 Jan 2018, 08:27

13 Mar 2018, 11:06

tandraschko wrote:
25 Aug 2014, 10:46
Set preventPaste to false.

But, e.g. if you only allow numbers and paste a text, it won't be removed. It's just a keyfilter, no mask.
Is there any way to apply filter to paste also? eg. when I paste text on number only field??

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

13 Mar 2018, 11:20

No. It's a keyfilter, not a mask. I would use inputMask or something.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

nandish
Posts: 7
Joined: 30 Jan 2018, 08:27

13 Mar 2018, 11:30

tandraschko wrote:
13 Mar 2018, 11:20
No. It's a keyfilter, not a mask. I would use inputMask or something.
Ya, but inputMask is a separate input field I need to add filter to existing one's . And does inputMask allows RegExp in mask field?

flawesome
Posts: 6
Joined: 22 Apr 2022, 10:05

16 May 2022, 10:00

I've recently faced the exact same issue.

For some reason the keyFilter in combination with a custom filter does not accept any pasting at all.
You can refer to this github issue as well:
https://github.com/primefaces/primeng/issues/4850

You can workaround by simply defining a paste-event for the input field.
If you have issues with that you can take a look at the following stackblitz example.
There are several events defined such as the paste-event.
https://stackblitz.com/edit/github-a94a ... onent.html


Btw. bare in mind that when you work with more complex regex (e.g. for validation of credit card number or ip address) you probably have to enable the "pValidateOnly" property.
Otherwise you won't be able to enter any key because on every key stroke the regex tries to validate which will most probably fail and blocks the input.

jepsar
Posts: 166
Joined: 03 Sep 2014, 11:41
Location: NL / BE
Contact:

19 May 2022, 16:50

flawesome wrote:
16 May 2022, 10:00
I've recently faced the exact same issue.
This is about PrimeFaces, not PrimeNG.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House

flawesome
Posts: 6
Joined: 22 Apr 2022, 10:05

24 May 2022, 08:12

This is about PrimeFaces, not PrimeNG.
My fault, you are right...

Nevertheless it seems to be just the same behaviour in PrimeNG.

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests