Decimal separator and maxlength inputNumber

UI Components for JSF
Post Reply
maqjav
Posts: 2
Joined: 09 Feb 2015, 11:55

10 Jun 2016, 10:18

Hello.

I'm testing the new Primefaces 6.0 and the component p:inputNumber.

I have a couple of issues:

1º The atribute maxLength isn't working. If I set maxlength 5 it allows me to type more than 5 characters.

Code: Select all

<p:inputNumber maxlength="5" value="#{bean.number1}" />
2º Using maxValue I can control the length of the field, however I don't know how to disable the decimal formatter. I tried with decimalPlaces="0" and decimalSeparator="" but they are ignored.
Ideas?

I'm trying to write a number of 5 digits in my inputNumber without decimal separators.

Thanks.

hsntpn
Posts: 15
Joined: 18 Mar 2016, 21:24

17 Jun 2016, 13:14

you must use javascript in there because you are working on client side

Code: Select all

  <p:inputText onkeyup="var pos = this.selectionStart;
                    var size = this.value.length;
                    this.value = this.value.replace(/[^0-9]+/g, '');
                    if (this.value.length > 5)
                        this.value = this.value.substring(0, 4);
                    if (size > this.value.length)
                    {
                        this.selectionStart = pos - 1;
                        this.selectionEnd = pos - 1;
                    } else
                    {
                        this.selectionStart = pos;
                        this.selectionEnd = pos;
                    }"/>

raho
Posts: 27
Joined: 05 Feb 2016, 21:08

19 Aug 2016, 13:57

You can even use p:inputMask like this:

Code: Select all

<p:inputMask id="5digitnumber" value="#{bean.value}" mask="99999"/>
PF 12.0.4
WildFly 23.0.2.Final

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 65 guests