Sha256: a488ac6c4e2341c2344b86a4d53a8eb4d29ee9aaca95c807a6ceb422ebd97210

Contents?: true

Size: 826 Bytes

Versions: 3

Compression:

Stored size: 826 Bytes

Contents

import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  static get targets () {
    return ['dateInput', 'startDateInput', 'endDateInput']
  }

  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) {
    this.startDateInputTarget.value = value
  }

  setEndDateInputValue (value) {
    this.endDateInputTarget.value = value
  }

  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

3 entries across 3 versions & 1 rubygems

Version Path
headmin-0.4.2 app/assets/javascripts/headmin/controllers/date_range_controller.js
headmin-0.4.1 app/assets/javascripts/headmin/controllers/date_range_controller.js
headmin-0.4.0 app/assets/javascripts/headmin/controllers/date_range_controller.js