Skip to content

Directive on text input with mask: separator.0 + leadZero=true changes numeric form control type to string #1530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LoadedWithHay opened this issue Apr 28, 2025 · 0 comments

Comments

@LoadedWithHay
Copy link

LoadedWithHay commented Apr 28, 2025

🐞 bug report

Is this a regression?

No

Description

When using mask directive with expression: separtor.N (for example: separator.0) with flag [leadZero]=true and using Angular Reactive Forms, a form control is changing it's type from number to string.
It's caused by the method _toNumber: It checks if it's a SEPARATOR expression and if leadZero is truthy.
Why is that? I think the form control type shouldn't be changed via mask. Especially by the SEPARATOR expression mask which should be always a number?
Is this a desired behaviour?

My problem is that if a user is typing for example 23 in an input, the control.valueChanges output is "23" string, but should be a number.

this.control.valueChanges.subscribe(console.log) // <--- displays "23" string instead of 23 number

Image

🔬 Minimal Reproduction

<input
    mask="separator.0"
    [leadZero]="true"
    formControlName="myNumericFormControl"
/>

🌍 Your Environment

Angular Version:

latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants