primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Component: InputNumber - maxlength input param doesn't limit number of numbers that user can type

Open BobMakhlin opened this issue 1 year ago • 7 comments

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

  1. Create inputNumber with [maxlength]=5
  2. Type number with 6+ digits
  3. Observe result

Expected behavior

maxlength shouldn't allow user to input amount of numbers, bigger that was passed through input param

BobMakhlin avatar Jan 04 '24 16:01 BobMakhlin

Hello @BobMakhlin, the problem has been resolved in upcoming releases. Unfortunately, we cannot contribute to version v15-lts as it is outdated.

mou-taha avatar Jan 05 '24 08:01 mou-taha

@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 avatar Jan 10 '24 10:01 BobMakhlin

@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.

mou-taha avatar Jan 10 '24 17:01 mou-taha

Could someone suggest alternative way to resolve the issue with primeng 15 ?

nrevurucollegecraft avatar Jan 22 '24 14:01 nrevurucollegecraft

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));
}

} }

nrevurucollegecraft avatar Jan 23 '24 16:01 nrevurucollegecraft

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

dougmbarcellos avatar Apr 26 '24 18:04 dougmbarcellos

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!

github-actions[bot] avatar Aug 25 '24 01:08 github-actions[bot]

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!

github-actions[bot] avatar Sep 01 '24 01:09 github-actions[bot]

at least we tried

dougmbarcellos avatar Sep 01 '24 02:09 dougmbarcellos