Skip to content

Commit

Permalink
Merge pull request #311 from hansi90/cleave_field
Browse files Browse the repository at this point in the history
Cleave field fixed
  • Loading branch information
icebob authored Oct 11, 2017
2 parents e312446 + 6a171e3 commit dfe823c
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/fields/optional/fieldCleave.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", :id="getFieldID(schema)")
input.form-control(type="text", :value="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", :id="getFieldID(schema)")
</template>

<script>
Expand All @@ -16,7 +16,7 @@ export default {
},
mounted() {
this.$nextTick(function () {
this.$nextTick(function() {
if (window.Cleave) {
this.cleave = new window.Cleave(this.$el, defaults(this.schema.cleaveOptions || {}, {
// Credit Card
Expand All @@ -39,17 +39,37 @@ export default {
prefix: null,
numericOnly: false,
uppercase: false,
lowercase: false
lowercase: false,
maxLength: 0
}));
if (this.cleave.properties && this.cleave.properties.hasOwnProperty("result")) {
this.$watch("cleave.properties.result", () => {
this.value = this.cleave.properties.result;
});
} else {
this.$el.addEventListener("input", this.inputChange);
}
} else {
console.warn("Cleave is missing. Please download from https://github.com/nosir/cleave.js/ and load the script in the HTML head section!");
}
});
},
methods: {
inputChange() {
this.value = this.$el.value;
}
},
beforeDestroy() {
if (this.cleave)
if (this.cleave) {
this.cleave.destroy();
this.$el.removeEventListener("input", this.inputChange);
}
}
};
</script>
Expand Down

0 comments on commit dfe823c

Please sign in to comment.