Sha256: 241b6511fbb244a63445eb69be6e1d219820bf2840b0a973e57121ceda5d8286

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

Stimulus.register("datepicker", class extends Controller {
  static targets = [ "input", "span" ]

  connect() {
    const now = moment.tz(timeZone)
    const format = "YYYY-MM-DD"

    function toDate(time) {
      return moment.tz(time.format(format), timeZone)
    }

    const datePicker = $(this.element).daterangepicker({
      singleDatePicker: true,
      locale: { format: format },
      autoUpdateInput: false,
      autoApply: true,
      startDate: this.inputTarget.value.length > 0 ? moment.tz(this.inputTarget.value, timeZone) : now
    })

    // hack to start with empty date
    datePicker.on("apply.daterangepicker", (ev, picker) => {
      this.spanTarget.innerHTML = toDate(picker.startDate).format("MMMM D, YYYY")
      this.inputTarget.value = toDate(picker.startDate).utc().format()
      this.element.dispatchEvent(new Event("change", { bubbles: true }))
    })

    if (this.inputTarget.value.length > 0) {
      this.spanTarget.innerHTML = toDate(datePicker.data("daterangepicker").startDate).format("MMMM D, YYYY")
    }
  }
})

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
finery-3.0.3 app/assets/javascripts/blazer/controllers/datepicker_controller.js
finery-3.0.2 app/assets/javascripts/blazer/controllers/datepicker_controller.js
finery-3.0.1 app/assets/javascripts/blazer/controllers/datepicker_controller.js