-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathfieldPikaday.vue
70 lines (56 loc) · 1.72 KB
/
fieldPikaday.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
<template lang="jade">
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName")
</template>
<script>
import abstractField from "./abstractField";
import moment from "moment/min/moment.min";
import { defaults } from "lodash";
let inputFormat = "YYYY-MM-DD";
export default {
mixins: [ abstractField ],
data(){
return {picker: null};
},
methods: {
getDateFormat() {
if (this.schema.pikadayOptions && this.schema.pikadayOptions.format)
return this.schema.pikadayOptions.format;
else
return inputFormat;
},
formatValueToField(value) {
if (value != null)
return moment(value, this.schema.format).format(this.getDateFormat());
return value;
},
formatValueToModel(value) {
if (value != null) {
let m = moment(value, this.getDateFormat());
if (this.schema.format)
value = m.format(this.schema.format);
else
value = m.toDate().valueOf();
}
return value;
}
},
mounted() {
this.$nextTick(() => {
if (window.Pikaday){
this.picker = new window.Pikaday(defaults(this.schema.pikadayOptions || {}, {
field: this.$el, // bind the datepicker to a form field
// trigger: , // use a different element to trigger opening the datepicker, see [trigger example][] (default to `field`)
}));
} else {
console.warn("Pikaday is missing. Please download from https://github.com/dbushell/Pikaday/ and load the script and CSS in the HTML head section!");
}
});
},
beforeDestroy() {
if (this.picker)
this.picker.destroy();
}
};
</script>
<style lang="sass">
</style>