Skip to content

Commit 3aec9af

Browse files
committed
Cleave field fixed.
1 parent 5099907 commit 3aec9af

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/fields/optional/fieldCleave.vue

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
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)")
2+
input.form-control(type="text", :value="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName", :id="getFieldID(schema)")
33
</template>
44

55
<script>
@@ -16,7 +16,7 @@ export default {
1616
},
1717
1818
mounted() {
19-
this.$nextTick(function () {
19+
this.$nextTick(function() {
2020
if (window.Cleave) {
2121
this.cleave = new window.Cleave(this.$el, defaults(this.schema.cleaveOptions || {}, {
2222
// Credit Card
@@ -39,17 +39,37 @@ export default {
3939
prefix: null,
4040
numericOnly: false,
4141
uppercase: false,
42-
lowercase: false
42+
lowercase: false,
43+
maxLength: 0
4344
}));
45+
46+
if (this.cleave.properties && this.cleave.properties.hasOwnProperty('result')) {
47+
this.$watch('cleave.properties.result', () => {
48+
this.value = this.cleave.properties.result;
49+
});
50+
} else {
51+
this.$el.addEventListener('input', this.inputChange)
52+
}
53+
4454
} else {
4555
console.warn("Cleave is missing. Please download from https://github.com/nosir/cleave.js/ and load the script in the HTML head section!");
4656
}
4757
});
4858
},
4959
60+
methods: {
61+
62+
inputChange() {
63+
this.value = this.$el.value;
64+
}
65+
},
66+
5067
beforeDestroy() {
51-
if (this.cleave)
68+
if (this.cleave) {
5269
this.cleave.destroy();
70+
this.$el.removeEventListener('input', this.inputChange);
71+
}
72+
5373
}
5474
};
5575
</script>

0 commit comments

Comments
 (0)