primeng
primeng copied to clipboard
Component: InputNumber - maxlength input param doesn't limit number of numbers that user can type
Describe the bug
<p-inputNumber formControlName="number" [max]="max" [maxFractionDigits]="2" [maxlength]="5" [min]="min" mode="decimal" />
The same as this issue.
Environment
Prod
Reproducer
No response
Angular version
15.2.8
PrimeNG version
15.4.14-lts
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
18.19.0
Browser(s)
Chrome
Steps to reproduce the behavior
- Create inputNumber with
[maxlength]=5
- Type number with 6+ digits
- Observe result
Expected behavior
maxlength
shouldn't allow user to input amount of numbers, bigger that was passed through input param
Hello @BobMakhlin, the problem has been resolved in upcoming releases. Unfortunately, we cannot contribute to version v15-lts as it is outdated.
@mou-taha, On the PrimeNG website (https://primeng.org/lts) it is stated that support for v15 LTS ends after the release of v18. This should mean that the version is still supported and not outdated. Or I'm wrong?
@BobMakhlin I don't think so. but I asked the community on Discord, and they informed me that I cannot contribute to v15lts because it is outdated.
Could someone suggest alternative way to resolve the issue with primeng 15 ?
this directive will help you to resolve the issue if you are using primeng 15
import { Directive, Input, HostListener, ChangeDetectorRef, } from '@angular/core'; import { NgModel } from '@angular/forms';
@Directive({ selector: '[maxLengthDirective]', }) export class MaxNumberLengthDirective { @Input() maxLength: number;
constructor(private ngModel: NgModel, private cdr: ChangeDetectorRef) {} @HostListener('onInput', ['$event']) onInput(event: any): void { const value = event.originalEvent.target.value; this.cdr.detectChanges();
if (this.maxLength && value && value.length > this.maxLength) {
const strValue = value.toString().slice(0, this.maxLength);
this.ngModel.control.patchValue(Number(strValue));
}
} }
Hello @BobMakhlin, the problem has been resolved in upcoming releases. Unfortunately, we cannot contribute to version v15-lts as it is outdated.
Could you tell which issue or pull-request this fix is related to?
I found no indication that the behavior was fixed.
Using the latest version of primeng (17.15.0) and @BobMakhlin example, the issue still occurs:
https://stackblitz.com/edit/ck5edm?file=src%2Fapp%2Fdemo%2Finput-number-numerals-demo.html
This issue has been automatically marked as stale. If this issue is still affecting you with the latest version, please leave any comment, and we will keep it open. We are sorry that we have not been able to prioritize it yet. If you have any new additional information, please include it with your comment!
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you for your understanding!
at least we tried