p:keyFilter not working as expected in Firefox

让人想犯罪 __ 提交于 2020-05-29 09:42:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/61466526/pkeyfilter-not-working-as-expected-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!