Skip to content
Merged
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
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