ankurk91 / vue-flatpickr-component

Vue.js component for Flatpickr datetime picker :calendar:
https://ankurk91.github.io/vue-flatpickr-component/
MIT License
965 stars 102 forks source link

EnableTime can not be dynamicly changed once rendered #259

Closed LukasOchmann closed 2 years ago

LukasOchmann commented 2 years ago

I'm submitting a ...

[X] Bug report => search github for a similar issue or PR before submitting
[ ] Feature request
[ ] Other, please describe

Tell about your platform

Current behavior EnableTime is not dynamicly changeable. Depending on the Select-Element we need to change the configuration for the flatpicker.

<template>
  <select @change="onSelectChange">
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
  </select>
  <flat-pickr :config="datePickerConfig" />
</template
const showDatePicker = ref(false)
const datePickerConfig = reactive({
  altInput: true,
  altInputClass: 'date-range flatpickr-input',
  wrap: true,
  dateFormat: 'Z',
  locale: 'de',
  mode: 'range',
  altFormat: 'dd.mm.yyyy',
  defaultHour: 8,
  enableTime: false,
})

const onSelectChange = (event) => {
  const value = event.target.value;
  if (value == 'A') {
     datePickerConfig.enableTime = true
    showDatePicker = true
  } else if(value == 'B') {
     datePickerConfig.enableTime = false
    showDatePicker = true
  } else {
     showDatePicker = false
  }
}

once the Datepicker is rendered with ether enabledTime=true or enabledTime=false it wont change its behaviour when the select triggers its change. It works as expected when the datepicker removed from the dom and rerenderd. In the Vue-Devtools i can see that the the component hat the right config.

Expected behavior The datePicker updates when enabledTime ist toggled.

Minimal reproduction of the problem with instructions you can use the html and js above.

ankurk91 commented 2 years ago

I dont think the parent library supports it. https://github.com/flatpickr/flatpickr

https://jsfiddle.net/23qsmhgz/

You may play with plain js version here.

LukasOchmann commented 2 years ago

yes true, it dose not support this: https://jsfiddle.net/fg7pk5ec/9/ I will create an issue/feature Request on the flatpicker-github. Thank you for the quick response