Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeNG p-inputNumber with currency does not force input only of numbers using mobile devices

Im using <p-inputNumber> tag from PrimeNG.

In computer view, the input only allows to enter numbers. If I press any letter with the keyboard, the letter will not be written on the input. All okey.

But, when Im using mobile device (android with chrome), the web browser allows me to write anything else.

I have been reading some posts about force input numeric with basic html <input> tag. But, as I said, I'm using primeng tag <p-inputNumber> with currency options:

<p-inputNumber [(ngModel)]="newExpenseAmount" [style]="{width: '100%'}" mode="currency" currency="EUR" locale="es-ES"></p-inputNumber>

¿Any way to make it works fine in mobile devices? ¿Any way to force numeric keyboard on mobile devices compatible with this primeng component?

like image 284
UrbanoJVR Avatar asked Oct 24 '25 15:10

UrbanoJVR


1 Answers

You can access the input itself and set the type:

HTML:

<p-inputNumber #input [(ngModel)]="newExpenseAmount" [style]="{width: '100%'}" mode="currency" currency="EUR" locale="es-ES"></p-inputNumber>

Class:

@ViewChild('input') public input: InputNumber

public ngAfterViewInit(): void {
    (this.input.input.nativeElement as HTMLElement).setAttribute("type", "tel");
}
like image 81
misha130 Avatar answered Oct 27 '25 04:10

misha130



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!