-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathfieldDateTimePicker.vue
71 lines (57 loc) · 1.77 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template lang="jade">
.input-group.date
input.form-control(type="text", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :placeholder="schema.placeholder", :readonly="schema.readonly", :name="schema.inputName")
span.input-group-addon
span.glyphicon.glyphicon-calendar
</template>
<script>
/* global $ */
import abstractField from "./abstractField";
import moment from "moment/min/moment.min";
import { defaults } from "lodash";
let inputFormat = "YYYY-MM-DD HH:mm:ss";
export default {
mixins: [ abstractField ],
methods: {
getDateFormat() {
if (this.schema.dateTimePickerOptions && this.schema.dateTimePickerOptions.format)
return this.schema.dateTimePickerOptions.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(function () {
if (window.$ && window.$.fn.datetimepicker) {
$(this.$el).datetimepicker(defaults(this.schema.dateTimePickerOptions || {}, {
format: inputFormat
}));
} 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>
<style lang="sass">
</style>