forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldCleave.vue
78 lines (71 loc) · 1.8 KB
/
fieldCleave.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<template lang="pug">
input.form-control(type="text", :value="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="fieldID")
</template>
<script>
import abstractField from "../abstractField";
import { defaults } from "lodash";
export default {
name: "field-cleave",
mixins: [abstractField],
data() {
return {
cleave: null
};
},
mounted() {
this.$nextTick(function() {
if (window.Cleave) {
this.cleave = new window.Cleave(
this.$el,
defaults(this.fieldOptions, {
// Credit Card
creditCard: false,
// onCreditCardTypeChanged: onCreditCardTypeChanged.bind(this),
// Phone
phone: false,
phoneRegionCode: "AU",
// Date
date: false,
datePattern: ["d", "m", "Y"],
// Numerals
numeral: false,
numeralThousandsGroupStyle: "thousand",
numeralDecimalScale: 2,
numeralDecimalMark: ".",
// General
blocks: [],
delimiter: " ",
prefix: null,
numericOnly: false,
uppercase: 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) {
this.cleave.destroy();
this.$el.removeEventListener("input", this.inputChange);
}
}
};
</script>