zero to the left of the number (type number)

Asked

Viewed 272 times

0

<input oninput="if (this.value.length > this.maxLength)
 this.value = this.value.slice(0, this.maxLength);
 validity.valid||(value='');" min="0" step="1" type="number"
 maxlength="9" formControlName="quantity" class="form-control"
 [ngClass]="item.controls['quantity'].errors ? 'has-error' : ''"
 (keydown)="onValueOrQuantityChanged(item)"
 (keyup)="onValueOrQuantityChanged(item)">

I have the html code above that inserts an input of type NUMBER. Together there is a javascript code that ensures that I do not type more than 9 numbers.

The problem is that when my application runs on Firefox, when typing zero(s) on the left, it is (are) dropped(s) after typing the 9 numbers.

Ex. by typing "000999999", zeros are discarded and I can type you 3 more numbers at the end of the value. But I want to keep these zeros.

OBS.: is happening only in Firefox.

  • it shows no error in console?

  • If it’s not causing any trouble, switch to type='text' and see if it solves.

  • @Máttheusspoo we are using as a requirement that the field cannot accept character other than number (requirement requested by client)

  • @Alvaroalves no error message

  • @Cris.tal in this case, put a mask on the field, or use a input.replace(/\D/g, '') at an event keyup.

  • If you want to keep the zeros, because you are using Slice?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.