0

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,
  });
Violet Shreve
  • 1,093
  • 7
  • 18
Veda
  • 577
  • 1
  • 6
  • 22

1 Answers1

1

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:

Violet Shreve
  • 1,093
  • 7
  • 18
  • I want to hide the picker only when "today" button is clicked. I believe this does for all change events. How do i achieve only for today button? – Veda Sep 13 '19 at 12:51