forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldDateTimePicker.vue
51 lines (46 loc) · 1.29 KB
/
fieldDateTimePicker.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
<template lang="pug">
.input-group.date
input.form-control(type="text", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="fieldID")
span.input-group-addon
span.glyphicon.glyphicon-calendar
</template>
<script>
/* global $ */
import abstractField from "../abstractField";
import { defaults } from "lodash";
import dateFieldHelper from "../../utils/dateFieldHelper";
export default {
name: "field-dateTimePicker",
mixins: [abstractField],
methods: {
...dateFieldHelper
},
mounted() {
this.$nextTick(() => {
if (window.$ && window.$.fn.datetimepicker) {
let input = this.$el.querySelector(".form-control");
$(this.$el)
.datetimepicker(
defaults(this.fieldOptions, {
format: this.getDefaultInputFormat()
})
)
.on("dp.change", () => {
this.value = input.value;
});
} else {
console.warn(
"Bootstrap datetimepicker library is missing. Please download from https://eonasdan.github.io/bootstrap-datetimepicker/ and load the script and CSS in the HTML head section!"
);
}
});
},
beforeDestroy() {
if (window.$ && window.$.fn.datetimepicker) {
$(this.$el)
.data("DateTimePicker")
.destroy();
}
}
};
</script>