Sha256: 11db4779f108859d4850872f62992ac120608a9b92da8e08fe4894b9a61250c9

Contents?: true

Size: 955 Bytes

Versions: 30

Compression:

Stored size: 955 Bytes

Contents

import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  update (event) {
    const flatpickr = event.target._flatpickr
    const startDate = flatpickr.selectedDates[0]
    const endDate = flatpickr.selectedDates[1]

    this.setStartDateInputValue(this.formatDate(startDate))
    this.setEndDateInputValue(this.formatDate(endDate))
  }

  setStartDateInputValue (value) {
    const startDateInput = this.startDateInput()
    startDateInput.value = value
  }

  setEndDateInputValue (value) {
    const endDateInput = this.endDateInput()
    endDateInput.value = value
  }

  startDateInput () {
    return this.element.nextElementSibling
  }

  endDateInput () {
    return this.startDateInput().nextElementSibling
  }

  formatDate (date) {
    if (date instanceof Date) {
      return date.toLocaleDateString('nl-BE', { day: '2-digit', month: '2-digit', year: 'numeric' })
    } else {
      return null
    }
  }
}

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
formstrap-0.4.5 app/assets/javascripts/formstrap/controllers/date_range_controller.js
headmin-0.6.3 app/assets/javascripts/headmin/controllers/date_range_controller.js
formstrap-0.4.4 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.4.3 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.4.2 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.3.5 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.3.4 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.3.3 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.3.2 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.3.1 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.3.0 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.2.1 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.2.0 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.1.3 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.1.2 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.1.1 app/assets/javascripts/formstrap/controllers/date_range_controller.js
formstrap-0.1.0 app/assets/javascripts/formstrap/controllers/date_range_controller.js
headmin-0.6.2 app/assets/javascripts/headmin/controllers/date_range_controller.js
headmin-0.6.1 app/assets/javascripts/headmin/controllers/date_range_controller.js
headmin-0.6.0 app/assets/javascripts/headmin/controllers/date_range_controller.js