Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Add a way to programmatically open and close the modal #241

Open
zhegwood opened this issue Nov 18, 2020 · 1 comment
Open

Add a way to programmatically open and close the modal #241

zhegwood opened this issue Nov 18, 2020 · 1 comment

Comments

@zhegwood
Copy link

Versions

  • vue: 2.6.11
  • vue-datetime: 1.0.0-beta.14
  • luxon: 1.25.0

Description:

There is no documented way to programmatically open and close the picker modal. One would expect this.$refs.datepicker.open() or this.$refs.datepicker.close(). If there is a way to do this right now, it is not in the docs.

Steps To Reproduce:

https://jsfiddle.net/6nwjyorp/

@darrenklein
Copy link

darrenklein commented Nov 22, 2020

@zhegwood One way to achieve this is by adding a ref to the Datetime component and then setting the isOpen property of the ref to true. I wanted to open the picker when the user clicked on a calendar icon adjacent to the input, so here's how I did it:

<template>
  <div class="datetime-input-container">
    <img
      @click="openDatetime"
      src="/icons/calendar.svg" />
    <Datetime
      ref="datetime"
      v-model="myModel.datetime"
      type="datetime"
      placeholder="Select datetime"
    />
  </div>
</template>

<script>
import { Datetime } from "vue-datetime";
import "vue-datetime/dist/vue-datetime.css";

export default {
  name: "Form",
  components: {
    Datetime
  },
  methods: {
    openDatetime() {
      this.$refs.datetime.isOpen = true;
    }
  }
}
</script>

(I've abstracted this from a more complex component, so forgive me if I left something out - but I think you'll get the idea).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants