Skip to content

Commit

Permalink
Merge pull request #141 from sumocoders/flatpickr
Browse files Browse the repository at this point in the history
Fix time pickers
  • Loading branch information
daphneslootmans authored Oct 2, 2024
2 parents 80f3c22 + 0c3133a commit d557080
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/js/Framework/DateTimePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Spanish } from 'flatpickr/dist/l10n/es.js'
import { Slovenian } from 'flatpickr/dist/l10n/sl.js'

export class DatePicker {
constructor (element) {
constructor (element, enableTime = false, noCalendar = false) {
this.element = element

let locale = document.documentElement.lang
Expand All @@ -31,7 +31,9 @@ export class DatePicker {

try {
this.element._flatpickr = flatpickr(this.element, {
locale: locale
locale: locale,
enableTime: enableTime,
noCalendar: noCalendar
})
} catch (ex) {
console.log('No translation found for ' + locale)
Expand Down
4 changes: 1 addition & 3 deletions src/js/Framework/DateTimePicker/DateTimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { DatePicker } from './DatePicker.js'

export class DateTimePicker extends DatePicker {
constructor (element) {
super(element)

this.element._flatpickr.config.enableTime = true
super(element, true)
}
}
5 changes: 1 addition & 4 deletions src/js/Framework/DateTimePicker/TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { DatePicker } from './DatePicker.js'

export class TimePicker extends DatePicker {
constructor (element) {
super(element)

this.element._flatpickr.config.enableTime = true
this.element._flatpickr.config.noCalendar = true
super(element, true, true)

element.parentNode.querySelector('[data-flatpicker-clear]').addEventListener('click', event => this.element._flatpickr.clear())
}
Expand Down

0 comments on commit d557080

Please sign in to comment.