Reputation: 607
I am using https://github.com/TrevorS/bootstrap3-datetimepicker-rails datetimepicker in my rails application. How do we close the widget after clicking on today button?
$(document).on('turbolinks:load', () => {
$(".form_datetime").datetimepicker({
timeZone: 'utc',
format: "YYYY-MM-DD HH:mm:ss UTCZ",
defaultDate: moment().tz('UTC'),
icons: {
today: 'todayText',
up: 'glyphicon glyphicon-chevron-up',
up: "fa fa-arrow-up",
down: "fa fa-arrow-down",
previous: " fa fa-arrow-left",
next: "fa fa-arrow-right"
},
showTodayButton: true,
ignoreReadonly: true,
allowInputToggle: true,
useCurrent: true,
});
Upvotes: 0
Views: 1160
Reputation: 1138
Watch for the dp.change
event, access the date picker through the data attribute of the anchor element, then call the hide function.
$(document).on("dp.change", () => {
$(".form_datetime").data("DateTimePicker").hide()
})
Documentation Source:
Upvotes: 1