Veda
Veda

Reputation: 607

How to hide the datetimepicker after clicking on today button using bootstrap-datetimepicker

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

Answers (1)

Violet Shreve
Violet Shreve

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

Related Questions