dbrekalo / vue-date-pick

Lightweight and mobile friendly date time picker based on Vue. Vue date pick emphasizes performance, elegant and usable UI on all screen sizes and simplicity of configuration. Has no dependencies on css frameworks or date libraries. Weighs less then 5KB.
https://dbrekalo.github.io/vue-date-pick/
MIT License
251 stars 84 forks source link

date-picker not working inside bootstrap-vue modal #28

Open alexraileanu opened 5 years ago

alexraileanu commented 5 years ago

related to #23. i have the same issue and was able to reproduce it.

when adding vue-date-pick inside a bootstrap-vue modal, the popup to select the date appears but fails to set the date.

example code:

<template>
  <div id="app">
    <button @click="showModal = !showModal">trigger modal</button>

    <b-modal ref="modal" v-model="showModal">
      <div>
        <vue-date-pick v-model="date" format="DD-MM-YYYY HH:mm" :pick-time="true"/>
      </div>
    </b-modal>
  </div>
</template>

<script>
import { BModal } from "bootstrap-vue";
import VueDatePick from "vue-date-pick";

import "vue-date-pick/dist/vueDatePick.css";
import "bootstrap/dist/css/bootstrap.css";
import "bootstrap-vue/dist/bootstrap-vue.css";

export default {
  name: "App",
  components: {
    BModal,
    VueDatePick
  },
  data() {
    return {
      date: "",
      showModal: false
    };
  }
};
</script>

as for versions, this has been tested with bootstrap-vue@2.0.0-rc.24, vue-date-pick@1.1.0 and vue@2.5.22.

pierreben commented 4 years ago

Hi,

I confirm the issue, I've created a Codesandbox to illustrate it: https://codesandbox.io/embed/vue-date-pick-28-dfllc.

The bug occurs on this line: https://github.com/dbrekalo/vue-date-pick/blob/master/src/vueDatePick.vue#L531 because the target of the click event is always the modal-content even when the user has clicked on the datepicker.

With a bootstrap b-form-input field in the modal, the event target is correct when I click on the input, so it look like it's related to CSS position.

Any idea on how to resolve this issue ? Many thanks

massmediagroup-73 commented 4 years ago

Have the same issue. If remove focusin event from ['click', 'keyup', 'focusin'].forEach( eventName => document.addEventListener(eventName, this.closeEventListener) ); The problem is gone.

qstiegler commented 4 years ago

@massmediagroup-73 Solution worked for me as well. Please fix it.

car3oon commented 4 years ago

The solution made by @massmediagroup-73 did the job for me as well. Any chances to fix this one anytime soon?

ralphskie commented 3 years ago

having this same issue right now. the solution above seems good but still just temporary.

JoaoHamerski commented 3 years ago

Have the same issue. If remove focusin event from ['click', 'keyup', 'focusin'].forEach( eventName => document.addEventListener(eventName, this.closeEventListener) ); The problem is gone.

Am i the only who dont have a clue how to implement it to work? Where i put this code?

EDIT: Nevermind, i just found out, here is a better explained answer:

The DatePick object has the following method:

addCloseEvents() {
    if (!this.closeEventListener) {
        this.closeEventListener = e => this.inspectCloseEvent(e);
        ['click', 'keyup', 'focusin'].forEach(
            eventName => document.addEventListener(eventName, this.closeEventListener)
        );
    }
},

You have to override the entire method removing the 'focusing' from the array.

Just add this:

import DatePick from 'vue-date-pick';

Vue.component('date-pick', mergeRecursive(DatePick, {
  methods: {
    addCloseEvents() {
      if (!this.closeEventListener) {
        this.closeEventListener = e => this.inspectCloseEvent(e);
        ['click', 'keyup'].forEach(
            eventName => document.addEventListener(eventName, this.closeEventListener)
        );
        }
      },
    }
}));

Here is the code to "mergeRecursive" function that merge two objects keeping the properties, add it to your application: https://stackoverflow.com/a/383245/14671559