From e456a1f96e738fa6ffe572839dd02657ca4e1457 Mon Sep 17 00:00:00 2001 From: Scott Fanetti Date: Wed, 26 Jul 2023 07:38:30 -0700 Subject: [PATCH] added changes to make the input work correctly on Android --- .gitignore | 2 ++ addon/components/masked-input.hbs | 1 + addon/components/masked-input.js | 26 ++++++++++++++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 7dd5db3..5f8ed0d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /node_modules/ # misc +/.idea/ /.env* /.pnp* /.sass-cache @@ -24,6 +25,7 @@ /.node_modules.ember-try/ /bower.json.ember-try /package.json.ember-try +/package-lock.json *.sublime-workspace yarn.lock diff --git a/addon/components/masked-input.hbs b/addon/components/masked-input.hbs index 8dc0a8f..b1baa31 100644 --- a/addon/components/masked-input.hbs +++ b/addon/components/masked-input.hbs @@ -9,4 +9,5 @@ {{on 'keypress' (fn this.onInputKeyPress)}} {{on 'change' (fn this.onInputChange)}} {{on 'paste' (fn this.onInputPaste)}} + {{on "beforeinput" this.onInputBeforeInput}} /> diff --git a/addon/components/masked-input.js b/addon/components/masked-input.js index 0f6620f..5825abd 100644 --- a/addon/components/masked-input.js +++ b/addon/components/masked-input.js @@ -75,6 +75,7 @@ export default class MaskedInputComponent extends Component { onInputChange(e) { const maskValue = this.inputMask.getValue(); if (e.target.value !== maskValue) { + this.inputMask.setValue(e.target.value); // Cut or delete operations will have shortened the value if (e.target.value.length < maskValue.length) { const sizeDiff = maskValue.length - e.target.value.length; @@ -138,15 +139,8 @@ export default class MaskedInputComponent extends Component { if (e.metaKey || e.altKey || e.ctrlKey || e.keyCode === 13 || e.keyCode === 9 || this.readonly) { return; } - - e.preventDefault(); - this.updateMaskSelection(); const key = e.key || String.fromCharCode(e.charCode); - if (this.inputMask.input(key)) { - e.target.value = this.inputMask.getValue(); - this.updateInputSelection(); - this.onChange(e); - } + this.handleCharInput(e, key) } @action @@ -169,6 +163,22 @@ export default class MaskedInputComponent extends Component { } } + @action + handleCharInput(evt, key) { + evt.preventDefault(); + this.updateMaskSelection(); + if (this.inputMask.input(key)) { + evt.target.value = this.inputMask.getValue(); + this.updateInputSelection(); + this.onChange(evt); + } + } + + @action + onInputBeforeInput(evt) { + this.handleCharInput(evt, evt.data); + } + updateMaskSelection() { this.inputMask.selection = getSelection(this.inputEl); }