vue-date-pick icon indicating copy to clipboard operation
vue-date-pick copied to clipboard

date-picker not working inside bootstrap-vue modal

Open alexraileanu opened this issue 5 years ago • 6 comments

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 [email protected], [email protected] and [email protected].

alexraileanu avatar Jun 26 '19 08:06 alexraileanu

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

pierreben avatar Sep 26 '19 07:09 pierreben

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

massmediagroup-73 avatar Oct 15 '19 15:10 massmediagroup-73

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

qstiegler avatar Oct 24 '19 02:10 qstiegler

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

car3oon avatar May 15 '20 09:05 car3oon

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

ralphskie avatar Dec 13 '20 04:12 ralphskie

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

JoaoHamerski avatar Dec 15 '20 20:12 JoaoHamerski