forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldPikaday.vue
45 lines (40 loc) · 1.17 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
<template lang="pug">
input.form-control(type="text", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName")
</template>
<script>
import abstractField from "../abstractField";
import { defaults } from "lodash";
import dateFieldHelper from "../../utils/dateFieldHelper";
export default {
name: "field-pikaday",
mixins: [abstractField],
data() {
return { picker: null };
},
methods: {
...dateFieldHelper
},
mounted() {
this.$nextTick(() => {
if (window.Pikaday) {
this.picker = new window.Pikaday(
defaults(this.fieldOptions, {
field: this.$el, // bind the datepicker to a form field
onSelect: () => {
this.value = this.picker.toString();
}
// 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>