Using a button click to toggle the vue-ctk-date-time-picker in VueJS

Currently, I am utilizing the Vue component - https://github.com/chronotruck/vue-ctk-date-time-picker within my own component. However, I am encountering an issue where I would like to maintain the component's original functionality while having a button outside of it to open and close it. It appears that the component does not have this feature built-in, so I am seeking assistance from anyone who could help with this.

You can view the code sandbox for reference here - Sanbox

Here is what I am currently implementing:

 <template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <vue-ctk-date-time-picker
      v-model="theDate"
      :name="'Date'"
      :format="'YYYY-MM-DD'"
      :formatted="'DD MMM, YYYY'"
      :only-date="true"
      :data-vv-as="'date'"
      :first-day-of-week="1"
      :range="true"
    >
    </vue-ctk-date-time-picker>
    <button>Open</button>
  </div>
</template>

The goal is to have a button external to the component that opens and closes the picker.

To give you more insight, here is the desired scenario:

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <vue-ctk-date-time-picker
      v-model="theDate"
      :name="'Date'"
      :format="'YYYY-MM-DD'"
      :formatted="'DD MMM, YYYY'"
      :only-date="true"
      :data-vv-as="'date'"
      :first-day-of-week="1"
      :no-value-to-custom-elem="false"
      :range="true"
    >
      <input type="text" /><button>Toggle</button>
    </vue-ctk-date-time-picker>
  </div>
</template>

The toggle button should control the visibility of the date picker.

Any assistance on this matter would be greatly appreciated.

Answer №1

---Updated---

Insert ref="pickerRef" into your date selector component

Adjust your <button> with the code below to activate and hide the date selector.

<vue-ctk-date-time-selector
      v-model="theDate"
      ref="pickerRef"
      :name="'Date'"
      :format="'YYYY-MM-DD'"
      :formatted="'DD MMM, YYYY'"
      :only-date="true"
      :data-vv-as="'date'"
      :first-day-of-week="1"
      :range="true"
      :no-value-to-custom-elem="false"
    >
</vue-ctk-date-time-selector>
<button
    type="button"
    @click="$refs.pickerRef.toggleDatePicker(), ($refs.pickerRef.persistent = true)"
    @blur="$refs.pickerRef.persistent = false"
>
    Activate
</button>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Spring REST service prevents Cross-Origin Requests with AJAX

Having Trouble Accessing Spring REST Service My spring service @RequestMapping(value = "/MAS/authenticate", method = RequestMethod.POST) public ResponseEntity<Map<String, String>> authenticate(@RequestBody Subject subject) { Map<String ...

Retrieve all records in which a Sequelize association uses hasOne

Currently, I am exploring the `sequalize association - hasOne` feature. However, I encountered an unexpected issue where all the rows from the `USER` table are being returned instead of just the rows from the `system_admin` table. Is this the intended beha ...

Ubuntu causing Bower to hang during dependency installation

I have encountered an issue while trying to install multiple dependencies using Bower on Ubuntu 14.04. The installation process gets stuck at a somewhat random point, usually during the installation of jQuery, closure-library, or closure compiler. Below ar ...

Replacing one <div> with another <div> using a clickable link within the divs

In one of my web pages, there is a div that I'll refer to as div1. Within this div, there is a link called 'Link1'. My goal is to click on Link1, triggering the replacement of div1 with div2. Inside div2 there will be another link, let&apos ...

What is the best way to define the active-class for nuxt-links with parameters?

Here is the issue I am facing with my code. I have a piece of code where the "/ " link does not get the active-class when the URL is domain.com/?standalone=true. <nuxt-link to="/" class="navBotton" exact-active-class="active&q ...

Expanding your npm knowledge: retrieve additional items

When trying to find out the versions of my packages, I utilize the following command. npm view <packagename> versions The output includes versions like: '2.4.0-2016-10-06-6743', '2.4.0-2016-10-07-6750', '2.4.0-2016-10-07- ...

How can we trigger the Skill bar effect upon scrolling to the section?

I have created a stunning Skill Bar that is functioning perfectly. However, I am looking to enhance the experience by having the skill bar effect trigger only when I scroll to that specific section. For example, as I navigate from the introduction section ...

Leverage the power of axios in your React application to retrieve information from an

I have been exploring how to use axios for fetching data from an API (https://reqres.in/) and displaying it in my React application. Previously, I used the fetch method in JavaScript to retrieve data from APIs. Despite trying various resources, I am unsure ...

What is the reason for the getter not being able to retrieve the value

I am experiencing an issue with a getter that returns an array of objects. The challenge I face is that I need to display past and current warnings in separate components. The getter currently only retrieves the current warning and ignores any past warnin ...

Effective methods for transferring parameters between two separate JavaScript files within an express.js application

Currently, I am working with Express.js and facing a challenge in passing parameters from one JavaScript file to another. How can this be accomplished? The two files involved are 1. process.js var WebPageTest = require('webpagetest'); var wpt ...

"Effortlessly transform a JSON string into a JSON Object with JavaScript - here's how

When I serialize my object using the ASP.net JavaScriptSerializer class and return it to the client side, how can I deserialize the string in JavaScript? ...

What sets apart initializing an Express app using "app = new Express()" compared to "app = express()"?

Throughout my experience, express apps have always been initialized like this: var express = require('express') var app = express() However, today I came across an example where a new operator was used: var Express = require('express&apos ...

Using NodeJS to Send JSON Data via HTTP POST Request

Issue with Sending JSON Data via Http Post in NodeJS const http = require('http'); const fs = require('fs'); var options = { hostname: 'www.postcatcher.in', port: 80, path: '/catchers/5531b7faacde130300002495&apo ...

Issue: Node.js unable to locate modules when directory path includes spaces in WindowsResolved Error: Module Un

Encountering a problem while attempting to execute an npm script on Windows with a path that includes spaces. The error message received is: E:\A B C\ny-project>npm start > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data ...

AJAX response from open cart is returning null JSON data

Hey there, I'm having a problem with my ajax request. It seems like I keep receiving a null value for json. Let me show you the JavaScript code... <script> $(document).ready( function() { $('#donate-box-submit').on('click' ...

Utilizing global NPM modules with Grunt Deploy instead of local installations

As a newcomer to npm and grunt, I am facing challenges with setting up our build server to utilize Grunt for generating output files in our project. The issue arises from the fact that due to Windows' 260 character path limit in TFS source control, we ...

Tips for bypassing the Windows tree command

C:\Users\client>npm install -g tree-cli + <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7b3b5a2a2eaa4abae87f7e9f1e9f3">[email protected]</a> updated 1 package in 2.374s C:\Users\client& ...

Exploring the power of QueryTask in ArcGIS JS API 3 for running multiple queries

When using QueryTask in ArcGIS JS Api 3, I encountered a challenge where I needed to execute multiple queries in one call. After referencing the documentation, I realized that this functionality was not directly supported. This is my current implementatio ...

Socket IO: Error - The call stack has exceeded the maximum size limit

Whenever a client connects to my node.js server, it crashes with a 'RangeError: Maximum call stack size exceeded' error. I suspect there's a recursive problem somewhere in my code that I can't seem to find. This is the code on my serve ...

The POST request to the localhost API endpoint resulted in a 404 Not Found error

Whenever I try to send a POST request to "/api/auth/signup" in my JavaScript application, I keep getting a 404 Not Found error. My goal is to create a MERN application for a Modern Real Estate Marketplace. This is the code snippet causing the is ...