Skip to content

Commit

Permalink
Fix for issue text-mask#480: Only set input element if we don't have …
Browse files Browse the repository at this point in the history
…it (text-mask#555)

* Fix for issue text-mask#480: Only set input element if we don't have it

* Remove unnecesary inputElement checks
  • Loading branch information
ajcrites authored and lozjackson committed Jun 21, 2017
1 parent 9b8d542 commit 2d98974
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions angular2/src/angular2TextMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export class MaskedInputDirective implements ControlValueAccessor, OnChanges {
}

writeValue(value: any) {
if (!this.inputElement) {
this.setupMask()
}
this.setupMask()

// set the initial value for cases where the mask is disabled
const normalizedValue = value == null ? '' : value
Expand All @@ -67,9 +65,7 @@ export class MaskedInputDirective implements ControlValueAccessor, OnChanges {
}

onInput(value) {
if (!this.inputElement) {
this.setupMask()
}
this.setupMask()

if (this.textMaskInputElement !== undefined) {
this.textMaskInputElement.update(value)
Expand All @@ -86,18 +82,20 @@ export class MaskedInputDirective implements ControlValueAccessor, OnChanges {
}

private setupMask() {
if (this.element.nativeElement.tagName === 'INPUT') {
// `textMask` directive is used directly on an input element
this.inputElement = this.element.nativeElement
} else {
// `textMask` directive is used on an abstracted input element, `ion-input`, `md-input`, etc
this.inputElement = this.element.nativeElement.getElementsByTagName('INPUT')[0]
}
if (!this.inputElement) {
if (this.element.nativeElement.tagName === 'INPUT') {
// `textMask` directive is used directly on an input element
this.inputElement = this.element.nativeElement
} else {
// `textMask` directive is used on an abstracted input element, `ion-input`, `md-input`, etc
this.inputElement = this.element.nativeElement.getElementsByTagName('INPUT')[0]
}

if (this.inputElement) {
this.textMaskInputElement = createTextMaskInputElement(
Object.assign({inputElement: this.inputElement}, this.textMaskConfig)
)
if (this.inputElement) {
this.textMaskInputElement = createTextMaskInputElement(
Object.assign({inputElement: this.inputElement}, this.textMaskConfig)
)
}
}
}
}
Expand Down

0 comments on commit 2d98974

Please sign in to comment.