Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/node_modules/

# misc
/.idea/
/.env*
/.pnp*
/.sass-cache
Expand All @@ -24,6 +25,7 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
/package-lock.json

*.sublime-workspace
yarn.lock
1 change: 1 addition & 0 deletions addon/components/masked-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
{{on 'keypress' (fn this.onInputKeyPress)}}
{{on 'change' (fn this.onInputChange)}}
{{on 'paste' (fn this.onInputPaste)}}
{{on "beforeinput" this.onInputBeforeInput}}
/>
26 changes: 18 additions & 8 deletions addon/components/masked-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down