Skip to content

Commit

Permalink
Fix Single-Decimal Auto-Complete on Blur
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielbuck committed May 7, 2024
1 parent e7f7c8e commit 10e4fcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida
maskExpression.length
)
);
if (precision > 1) {
if (precision > 0) {
el.value = this.suffix ? el.value.split(this.suffix).join('') : el.value;
const decimalPart = el.value.split(this.decimalMarker)[1] as string;
el.value = el.value.includes(this.decimalMarker)
Expand Down
13 changes: 13 additions & 0 deletions projects/ngx-mask-lib/src/test/emit-events.cy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe('Directive: Mask (emit-events)', () => {
cy.get('#pre').should('have.text', '7');
});

it('should add trailing zero when mask="separator.1" and leadZero="true"', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: 'separator.1',
leadZero: true,
},
imports: [CypressTestMaskModule],
});

cy.get('#masked').type('9').blur().should('have.value', '9.0');
cy.get('#pre').should('have.text', '3');
});

it('should emit event only when mask is correct with suffix separator2', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
Expand Down

0 comments on commit 10e4fcd

Please sign in to comment.