question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mask error after input value has been patched and not entered manually

See original GitHub issue

I’m using Angular v6.1.10 with ngx-mask v7.8.9 where the mask is for a phone number on an input. The input when patched using HTTP response data sets the field to be invalid with a mask validation error of { 'Mask error': true }, and the form control is not required.

<input type="text" mask="(000) 000-0000" formControlName="phone">
this.form = this.fb.group({
  phone: [
    this.phone, [FormControlValidators.phone]
  ],
  fax: [
   this.fax, [FormControlValidators.phone]
  ]
});

I tracked this into the MaskDirective where it checks for special characters, which if not found will do a comparison on the value length.

The value in the comparison viewed in console is the masked value and not the raw number that you get when you manually type the phone into the input.

When Value Patched

  1. The response data that is patched is 2509876543
  2. The value for comparison contains mask (250) 987-6543 on L180 which causes the error, and
  3. Validity of the model fails with { 'Mask error': true } on L181

When Value Manually Entered

  1. The entered data is 2509876543
  2. The value for comparison doesn’t contain mask 2509876543 on L180, and
  3. Validity of the model passes

It doesn’t seem to matter if the form controls are disabled or enabled, whether I patchValue or set the form group directly during initialization, or invoke markAsPristine or updateValueAndValidity afterwards. It only works if I manually enter the value provided from the response into the input, or when the user enables the form for editing I invoke this to get it to reset when it thinks is the model:

this.form.setValue(this.form.getRawValue());
this.form.get('phone').markAsPristine();
this.form.get('fax').markAsPristine();

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Thegrep01commented, Apr 9, 2019

@mtpultz if you need to disable mask validation use [validation]="false"

1reaction
jeffnwarnercommented, Mar 4, 2021

I seem to be having this issue as well. When I create a form with a patched in value I can’t save until I manually edit the field.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input Mask Guide | imaskjs
Instance of InputMask is returned when IMask constructor is called. To create new mask on element use: var mask = IMask(element, maskOptions);. Get/set...
Read more >
Solved: Input mask apply flexibility in character numbers?
I have a field that would get input values of two to three letters followed by one to four digits. The letters need...
Read more >
Control data entry formats with input masks - Microsoft Support
An input mask is a string of characters that indicates the format of valid input values. You can use input masks in table...
Read more >
Input Mask | WinForms Controls - DevExpress Documentation
Input masks are in effect only when an editor is focused. ... Use this mask type when an editor should accept values in...
Read more >
Use alpha channels, masks, and mattes in After Effects
The mask has no direct influence on the alpha channel of the layer. ... values to 1,000 and any value beyond 1000 was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found