anup9
anup9

Reputation: 29

p:keyFilter not working as expected in Firefox

I'm able to enter both the digits and special characters for the p input text.

How to restrict the field that can accept only digits? in all the browsers?

<p:message for="longitude" display="text"><p:autoUpdate/></p:message>
<p:inputText id="longitude" maxlength="18" style="width: 50%;" value="#{areaMB.longitude}">
<p:keyFilter regEx="/[0-9]/i" />
</p:inputText>

Browser Chrome Version 81.0.4044.113 (64-bit) - Only Digits are being able to enter in the field
Browser IE Version 11.0.9600 - Only Digits are being able to enter in the field

Problem But through Fire Fox

Browser Fire Fox 75.0 (64-bit) - Digits and Special characters are being able to enter in the field /

How to restrict the field that can accept only digits? in all the browsers?

The Issue only exists in the Browser Fire Fox and most of the users are using this browser.

Upvotes: 3

Views: 512

Answers (1)

Melloware
Melloware

Reputation: 12019

This KeyFilter Firefox issue was fixed in PrimeFaces 8.0: https://github.com/primefaces/primefaces/issues/5110

If you really need to restrict input to digits you can use p:inputNumber like this.

<p:inputNumber id="longitude" 
               maxlength="18" 
               style="width: 50%;" 
               value="#{areaMB.longitude}" 
               decimalPlaces="0"
               minValue="0" />

Remove minValue if you want to allow negative numbers.

Upvotes: 3

Related Questions