Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Trying to fix issue ,#1
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurk91 committed Sep 18, 2018
1 parent 25532ed commit ac3f95b
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/component.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<input type="text" @blur="onBlur">
<input type="text" @blur="onBlur" @input="onInput">
</template>

<script>
Expand Down Expand Up @@ -31,31 +31,25 @@
},
},
data() {
return {
onChangeFn: null
}
return {}
},
mounted() {
// Backup onChange callback
this.onChangeFn = this.options.onChange;
// Inject our onChange callback
let newOptions = jQuery.extend(true, {}, this.options, {onChange: this.onChange});
// Clone configs
let newOptions = jQuery.extend(true, {}, this.options);
// Lastly init the mask
jQuery(this.$el).mask(this.mask, newOptions);
// Set initial value
jQuery(this.$el).val(jQuery(this.$el).masked(this.value));
},
methods: {
/**
* Update v-model upon change triggered by plugin itself
* Update v-model upon change triggered by user
*/
onChange(...args) {
let toEmit = this.raw ? jQuery(this.$el).cleanVal() : arguments[0];
this.$emit('input', toEmit);
if (typeof this.onChangeFn === 'function') {
this.onChangeFn.call(this, ...args)
}
onInput(event) {
this.$nextTick(() => {
let toEmit = this.raw ? jQuery(this.$el).cleanVal() : event.target.value;
this.$emit('input', toEmit);
});
},
onBlur(event) {
this.$emit('blur', this.value)
Expand All @@ -72,7 +66,6 @@
},
beforeDestroy() {
jQuery(this.$el).unmask();
this.onChangeFn = null
}
}
</script>

0 comments on commit ac3f95b

Please sign in to comment.