Skip to content

Commit

Permalink
fix: keep min or last value on deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpam committed May 20, 2021
1 parent 82a3837 commit 79e124e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libs/ngx-masked-input/package.json
Original file line number Diff line number Diff line change
@@ -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)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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?.();
}

Expand Down

0 comments on commit 79e124e

Please sign in to comment.