changhuixu / ngx-digit-only

An Angular directive to only allow [0-9] in the input box when typing, pasting or drag/dropping.

Home Page:https://changhuixu.github.io/ngx-digit-only/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v3.0.0 allows non numeric inputs

crooksey opened this issue · comments

I recently upgraded to angular 12.00 (not sure if related) but on angular V12 when using digit-only v2.2.3 everything works as expected, using the following code:

Using angular forms with FormGroup

<input type="text" 
           digitOnly maxlength="3" inputmode="numeric" pattern="[0-9]*"  
           class="form-control" placeholder="Amount required?"
           id="qty" formControlName="qty">

I have also tried just using digitOnly with the same results.

However, when upgrading to v3.0.0 in the input field it allows me to enter anything, e.g. "aaa"

But the maxlength attribute is still honoured/validated.

Not sure what else may be of use to diagnose this further? But package.json is here:

    "@angular/animations": "~12.0.0",
    "@angular/cdk": "^12.0.0",
    "@angular/common": "~12.0.0",
    "@angular/compiler": "~12.0.0",
    "@angular/core": "~12.0.0",
    "@angular/forms": "~12.0.0",
    "@angular/google-maps": "^12.0.0",
    "@angular/localize": "^12.0.0",
    "@angular/platform-browser": "~12.0.0",
    "@angular/platform-browser-dynamic": "~12.0.0",
    "@angular/platform-server": "~12.0.0",
    "@angular/router": "~12.0.0",

I am not able to reproduce this problem.

myGroup = new FormGroup({
    qty: new FormControl(''),
  });
<div [formGroup]="myGroup">
    <input
      type="text"
      digitOnly
      maxlength="3"
      inputmode="numeric"
      pattern="[0-9]*"
      class="form-control"
      placeholder="Amount required?"
      id="qty"
      formControlName="qty"
    />
  </div>

Could you try the demo site to see if you come across the same issue?
May I know your browser version?

Hi, what I have done is manually include the directive inside my own project, and use it that way, it was only when using as part of the package I got this issue, will close for now, but really strange. I did try removing node_modules and clearing my cache in-case that was causing any issues, but it still persisted.