forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldCleave.vue
103 lines (94 loc) · 2.22 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template lang="jade">
input.form-control(type="text")
</template>
<script>
import abstractField from "./abstractField";
import { defaults } from "lodash";
export default {
mixins: [abstractField],
data() {
return {
cleave: null
};
},
watch: {
/*model: {
get(){
if (window.Cleave) {
console.log("get model", this.model);
}
},
set(value) {
if (window.Cleave) {
console.log("set model", this.model, value);
}
}
}*/
},
methods: {
/*formatValueToField(){
console.log(" 1 formatValueToField",this.cleave);
if (this.cleave) {
return this.cleave.getRawValue();
}else{
console.log("fail")
// this.cleave.element.value = "";
return "";
}
},*/
/*formatValueToModel(newValue){
console.log(" 2 formatValueToModel");
this.cleave.setRawValue(newValue);
return newValue;
}*/
// onCreditCardTypeChanged(type){
// let onCreditCardTypeChanged = this.schema.onCreditCardTypeChanged;
// if (typeof(onNewTag) == "function") {
// onNewTag(newTag, id, this.options, this.value);
// }
// }
/*onChange(value) {
console.log(value);
if (value.length === 1) {
// Single value
this.value = parseFloat(value[0]);
} else {
// Array (range)
this.value = [parseFloat(value[0]), parseFloat(value[1])];
}
}*/
},
ready() {
if (window.Cleave) {
this.cleave = new Cleave(this.$el, defaults(this.schema.cleaveOptions || {}, {
// 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
}));
} else {
console.warn("Cleave is missing. Please download from https://github.com/nosir/cleave.js/ and load the script in the HTML head section!");
}
}
};
</script>
<style lang="sass">
.vue-form-generator .field-cleave {}
</style>