scinote-web/app/javascript/vue/shared/date_picker.vue

47 lines
1.3 KiB
Vue
Raw Normal View History

<template>
<div class="datepicker sci-input-container right-icon">
<input
@change="update"
type="datetime"
class="form-control calendar-input sci-input-field"
:id="this.selectorId"
2023-08-23 17:59:21 +08:00
:placeholder="placeholder || 'dd/mm/yyyy'"
/>
2023-06-08 14:33:37 +08:00
<i class="sn-icon sn-icon-calendar"></i>
</div>
</template>
<script>
2023-08-23 17:59:21 +08:00
import '../../../../vendor/assets/javascripts/bootstrap-datetimepicker';
export default {
name: 'DatePicker',
props: {
2023-08-23 17:59:21 +08:00
placeholder: { type: String },
selectorId: { type: String, required: true },
useCurrent: { type: Boolean, default: true },
defaultValue: { type: Date, default: null }
},
mounted() {
$("#" + this.selectorId).datetimepicker(
{
useCurrent: this.useCurrent,
ignoreReadonly: this.ignoreReadOnly,
locale: this.i18n.locale,
2023-08-23 17:59:21 +08:00
format: $('body').data('datetime-picker-format'),
date: this.defaultValue
}
);
$("#" + this.selectorId).on('dp.change', (e) => this.update(e.date))
},
methods: {
update(value) {
this.$emit('change', (value._isAMomentObject) ? value.toDate() : '');
},
isValidDate(date) {
return (date instanceof Date) && !isNaN(date.getTime());
},
}
}
</script>