ngx-mask icon indicating copy to clipboard operation
ngx-mask copied to clipboard

For empty number input mask sets input value as 0 instead of null

Open dianadomino24 opened this issue 3 years ago • 3 comments

Description

When user deletes all digits from number input, input becomes empty but if inspect the input value in console or debugger, its value is actually 0 instead of null. This creates bug when input has required validator which shows that empty input is valid (because it's value is set as 0) whereas it should be invalid.

When I set debugger in writeValue method of input, I see that input value null is transformed into 0 after this._maskService.applyValueChanges call.

🔬 Minimal Reproduction

<input mask="separator.2" [(ngModel)]="value" />

Angular Version:


    "ngx-mask": "^11.1.4",
    "@angular/cdk": "12.2.3",
    "@angular/common": "^12.2.3",
    "@angular/compiler": "^12.2.3",
    "@angular/core": "^12.2.3",
    "@angular/forms": "^12.2.3",

Video of debugger

https://user-images.githubusercontent.com/63780561/165263365-99a66ea1-6e01-40ec-b64d-97d0a74f52fc.mov

dianadomino24 avatar Apr 26 '22 10:04 dianadomino24

+1

zmays avatar May 20 '22 14:05 zmays

hi @dianadomino24 can you please provide all your code for reproducing this issue ?

xakeppok avatar Jun 09 '22 14:06 xakeppok

@xakeppok Hi, I'm a colleague of Diana, I'll ask her to provide minimal reproduction on StackBlitz in coming days

ZhidkovGV avatar Jun 15 '22 22:06 ZhidkovGV

Hey @xakeppok! Sorry for the long reply) Here is the minimal reproduction:

Please, note that when I delete everything from the input, the value is set to 0 instead of null. So I can't distinguish whether user filled in 0 (which is valid) or it's empty input (which is invalid).

image

dianadomino24 avatar Oct 03 '22 18:10 dianadomino24

@dianadomino24 @zmays Thanks for your using Ngx-Mask. Please update to latest version. It example, all work as expected - https://stackblitz.com/edit/angular-1hp1gb?file=src%2Fmain.ts

andriikamaldinov1 avatar May 25 '23 08:05 andriikamaldinov1

In empty text box if I am pressing period key "." its not appearing. I am using ngx-mask: 15.1.0", with angular 15

subhabrata2017 avatar Nov 23 '23 19:11 subhabrata2017