diff --git a/libs/ngx-masked-input/package.json b/libs/ngx-masked-input/package.json index 5fec2c6..0b515c9 100644 --- a/libs/ngx-masked-input/package.json +++ b/libs/ngx-masked-input/package.json @@ -1,7 +1,7 @@ { "name": "@stumpam/ngx-masked-input", "license": "MIT", - "version": "3.2.2", + "version": "3.2.3", "description": "Angular Date picker with masked input.", "homepage": "https://github.com/stumpam/ngx-masked-input", "author": "Martin Štumpa (https://github.com/stumpam)", diff --git a/libs/ngx-masked-input/src/lib/directives/masked-input/masked-input.directive.ts b/libs/ngx-masked-input/src/lib/directives/masked-input/masked-input.directive.ts index e6072bb..e788c25 100644 --- a/libs/ngx-masked-input/src/lib/directives/masked-input/masked-input.directive.ts +++ b/libs/ngx-masked-input/src/lib/directives/masked-input/masked-input.directive.ts @@ -245,7 +245,12 @@ export class MaskedInputDirective implements ControlValueAccessor { } onBlur() { - const value = +this.field.nativeElement.value.replace(/\D/g, ''); + const elValue = this.field.nativeElement.value; + let value = +elValue.replace(/\D/g, ''); + + if (elValue === '' && !this._options.enableEmpty) { + value = this._options.min ?? +this.previousValue; + } if ( this._options.min && @@ -263,6 +268,10 @@ export class MaskedInputDirective implements ControlValueAccessor { this.onInput(this._options.max.toString()); } + if (elValue === '' && !this._options.enableEmpty) { + this.onInput(value.toString()); + } + this.touchedFn?.(); }