Skip to content

Commit

Permalink
fix(input-mask): keep model value if deactiveMask is set (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
vt-allianz authored and GitHub Enterprise committed Jun 21, 2022
1 parent 13425fe commit 388dba6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { Component } from '@angular/core';
styleUrls: ['./mask-deactivate-example.css'],
})
export class MaskDeactivateExampleComponent {
modelVal!: string;
templateModel: string = 'deactivate';
modelVal = 'SSAAAAA';
templateModel = 'deactivate';
}
15 changes: 15 additions & 0 deletions projects/ng-aquila/src/mask/mask.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ describe('NxMaskDirective', () => {
assertInputValue(nativeElement, 'test', 'test');
expect(testInstance.modelVal).toBe('test');
});

it('should keep preset model value if deactiveMask set', () => {
createTestComponent(PresetDeactiveMaskComponent);
setMask('AA-AA');

fixture.detectChanges();
expect(testInstance.modelVal).toBe('AAAA');
});
});

it('should not accept characters if mask is filled up', () => {
Expand Down Expand Up @@ -975,6 +983,13 @@ class ConfigurableMaskComponent extends MaskTest {}
})
class ValidationMaskComponent extends MaskTest {}

@Component({
template: ` <input [nxMask]="mask" [(ngModel)]="modelVal" [deactivateMask]="true" /> `,
})
class PresetDeactiveMaskComponent extends MaskTest {
modelVal = 'AAAA';
}

@Component({
template: `<input [nxMask]="mask" [separators]="separators" />`,
})
Expand Down
2 changes: 1 addition & 1 deletion projects/ng-aquila/src/mask/mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export class NxMaskDirective implements ControlValueAccessor, Validator {

this.cvaModelChange.next(value);
if (this.deactivateMask) {
this.updateValue(this.getUnmaskedValue());
this.updateValue(value || this.getUnmaskedValue());
} else {
this.updateValue(this.getMaskedString(value));
}
Expand Down

0 comments on commit 388dba6

Please sign in to comment.