Skip to content
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

feat(#917): function done is added [ref: 917] #985

Merged
merged 10 commits into from
Mar 30, 2022
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<a name="13.1.4"></a>

# 13.1.4 (2022-03-30)

### Feature

- Function maskFilled is added
- Feature ([#917](https://github.com/JsDaddy/ngx-mask/issues/917))

<a name="13.1.3"></a>

# 13.1.3 (2022-03-28)
Expand All @@ -7,7 +16,6 @@
feature ([#940](https://github.com/JsDaddy/ngx-mask/issues/940))
Fixed ([#965](https://github.com/JsDaddy/ngx-mask/issues/965))


<a name="13.1.2"></a>

# 13.1.2 (2022-01-20)
Expand Down Expand Up @@ -37,7 +45,7 @@ Fixed ([#965](https://github.com/JsDaddy/ngx-mask/issues/965))
### Test/CI fixes

- Enable cypress component testing

<a name="13.0.1"></a>

# 13.0.1 (2021-12-15)
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,11 @@ You can pass into mask pattern with `||`.
```html
<input mask="(00) 0000-0000||(00) 0 0000-0000" />
```

### Function maskFilled

#### Usage

```html
<input mask="0000" (maskFilled)="maskFilled()" />
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "13.1.3",
"version": "13.1.4",
"description": "awesome ngx mask",
"license": "MIT",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mask-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "13.1.3",
"version": "13.1.4",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
4 changes: 3 additions & 1 deletion projects/ngx-mask-lib/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InjectionToken } from '@angular/core';
import { InjectionToken, EventEmitter } from '@angular/core';

export interface IConfig {
suffix: string;
Expand All @@ -18,6 +18,7 @@ export interface IConfig {
allowNegativeNumbers: boolean;
leadZeroDateTime: boolean;
triggerOnMaskChange: boolean;
maskFilled: EventEmitter<void>;
patterns: {
[character: string]: {
pattern: RegExp;
Expand Down Expand Up @@ -53,6 +54,7 @@ export const initialConfig: IConfig = {
specialCharacters: ['-', '/', '(', ')', '.', ':', ' ', '+', ',', '@', '[', ']', '"', "'"],
leadZeroDateTime: false,
triggerOnMaskChange: false,
maskFilled: new EventEmitter<void>(),
patterns: {
'0': {
pattern: new RegExp('\\d'),
Expand Down
8 changes: 8 additions & 0 deletions projects/ngx-mask-lib/src/lib/mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {
} from '@angular/forms';
import {
Directive,
EventEmitter,
forwardRef,
HostListener,
Inject,
Input,
OnChanges,
Output,
SimpleChanges,
} from '@angular/core';
import { DOCUMENT } from '@angular/common';
Expand Down Expand Up @@ -78,6 +80,8 @@ export class MaskDirective implements ControlValueAccessor, OnChanges, Validator

@Input() public triggerOnMaskChange: IConfig['triggerOnMaskChange'] | null = null;

@Output() public maskFilled: IConfig['maskFilled'] = new EventEmitter<void>();

private _maskValue: string = '';

private _inputValue!: string;
Expand Down Expand Up @@ -291,6 +295,10 @@ export class MaskDirective implements ControlValueAccessor, OnChanges, Validator
}
}
}
if (value) {
this.maskFilled.emit();
return null;
}
return null;
}

Expand Down
44 changes: 44 additions & 0 deletions projects/ngx-mask-lib/src/test/complete-mask.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { NgxMaskModule } from '../lib/ngx-mask.module';

@Component({
selector: 'mask-test',
template: ` <input (maskFilled)="maskFilled()" mask="0000" [formControl]="form" /> `,
})
export class TestMaskComponent {
public form: FormControl = new FormControl('');

public isMaskFilled = false;

public maskFilled(): void {
this.isMaskFilled = true;
}
}

describe('Directive: Mask (Function maskFilled)', () => {
let fixture: ComponentFixture<TestMaskComponent>;
let component: TestMaskComponent;
let maskFilledSpy: jasmine.Spy<jasmine.Func>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestMaskComponent],
imports: [ReactiveFormsModule, NgxMaskModule.forRoot()],
});
fixture = TestBed.createComponent(TestMaskComponent);
component = fixture.componentInstance;
fixture.detectChanges();
maskFilledSpy = spyOn(component, 'maskFilled').and.callThrough();
});
it('should call function maskFilled and isMaskFilled should be true', () => {
component.form.setValue('9999');
expect(component.isMaskFilled).toBeTrue();
expect(maskFilledSpy).toHaveBeenCalledOnceWith();
});
it('isMaskFilled should be false', () => {
component.form.setValue('999');
expect(component.isMaskFilled).toBeFalse();
});
});