What is the best way to show a datepicker when a button is clicked in vuetify?

Here is the structure of my script:

===========--=========--=============--===============

<template> 
  <v-card
    max-width="1200"
    class="mx-auto"
  >
      <v-row>
        <v-col cols="12" sm="6" md="4">
          <v-menu
            ref="menu"
            v-model="menu"
            :close-on-content-click="false"
            :return-value.sync="date"
            transition="scale-transition"
            offset-y
            min-width="290px"
          >
            <template v-slot:activator="{ on }">
              <v-text-field
                v-model="date"
                label="Picker in menu"
                prepend-icon="event"
                readonly
                v-on="on"
              ></v-text-field>
            </template>
            <v-date-picker v-model="date" no-title scrollable>
              <div class="flex-grow-1"></div>
              <v-btn text color="primary" @click="menu = false">Cancel</v-btn>
              <v-btn text color="primary" @click="$refs.menu.save(date)">OK</v-btn>
            </v-date-picker>
          </v-menu>
        </v-col>
      </v-row>
  </v-card>
</template>
<script>
  export default {
    data: () => ({
      date: new Date().toISOString().substr(0, 10),
      menu: false,
      modal: false,
      menu2: false,
    }),
  }
</script>

The current output can be found here : https://i.stack.imgur.com/SEUDF.png

While the functionality works, I am interested in making a change. Instead of having the datepicker appear within a menu, I would like it to show up when a button is clicked as shown here: https://i.stack.imgur.com/cjIr2.png

What steps should I take to achieve this?

Answer №1

Revise your code by substituting

<v-text-field
   v-model="date"
   label="Picker in menu"
   prepend-icon="event"
   readonly
   v-on="on"></v-text-field>

with

<v-btn v-on="on">OPEN DATEPICKER</v-btn>

Answer №2

Here is a possible solution for you to consider.

<v-text-field
v-model="date"
label="Picker in menu"
prepend-icon="event"
readonly
>
 <template v-slot:append-outer>
  <v-btn
  icon
  color="indigo"
  v-bind="attrs"
  v-on="on"
  >
   <v-icon>mdi-calendar</v-icon>
  </v-btn>
 </template>

</v-text-field>

Note: If needed, remember to include attrs as shown here

<template v-slot:activator="{ on }">

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

Error: Unable to iterate through the {(intermediate value)}. It's not a function

Snippet of the original code: const genreOptions = [{{ genreOptions | json_encode | raw }}].map((type , label) => ({value: type, label: label})); Piece of debugging code: const genreOptions = { "Horror": "Kork ...

Interconnected properties with varying behaviors in Vue versions 1 and 2

Encountering a problem with input boxes having formatted numbers and computed properties when using Vue 2. Whenever an input is changed, Vue automatically recomputes the number, making it difficult to type in exactly what is needed. new Vue({ el: ' ...

Guide to placing an icon next to a label with Vue Bootstrap

I'm working with a Vue Bootstrap input field setup like this: <b-form-group label="Name" label-for="name"> <validation-provider #default="{ errors }" name="Mapping Name" rules="required ...

Error: Failed to load chunk (VueJS + Webpack) - Please try again

Currently, I am working on a project that involves Wordpress and VueJS 3 with a Webpack 5.43 build. Whenever a new version is deployed on the production environment and a visitor already has a tab open on the website, I encounter the following error messag ...

Tips for adding comments to VueJs Single-File-Components

As I develop my VueJs app with typescript, I have transitioned to using Vue's new script setup syntax for my single file components (SFC). However, I am unsure of the proper way to write comments that will show up in VSCode's intellisense. I aim ...

In VueJS, the v-for directive allows you to access both parameters and the event object within

Imagine having nested elements that repeat using v-for in the following structure: <div id="container"> <div v-for="i in 3"> <div v-for="j in 3" v-on:click="clicked(i,j)"> {{i+&a ...

What is the best way to emphasize a link to the current page in vue.js?

I am working on a sidebar feature that displays several dynamically generated links (similar to creating notes and then linking to them): https://i.stack.imgur.com/1lxcy.png Users can add a new note by clicking the 'Add stage' button. The list ...

The vue-router in Vue 3 is encountering an issue with the "createWebHistory" function, as it could not

I recently upgraded my Laravel 8 project to use Laravel Mix v6 in order to support Vue 3. However, I encountered an issue with the createWebHistory method from vue-router 4. In my package.json file: { "private": true, "scripts" ...

Personalized message on Vuetify slider

Is there a way to customize the message displayed on a Vuetify slider? https://i.stack.imgur.com/6Xdsm.png I want to include text like 'The number is: 8' <v-slider class='slider' step="1" thumb- ...

What is the best way to set up a Vue bus to handle global events?

I am working on a Vue project within a Node/Webpack/Vue Router environment and attempting to set up a global event handler or bus. However, I am running into an issue where it is showing as undefined. Below is how I have set it up: main.js: //Defining th ...

Support for Vue 3.4 same-name shorthand has been added to VS Code

After upgrading my Vue 3 project to version 3.4, I encountered an issue with vs-code highlighting same-name shorthand as an error, even though it was functioning correctly in my code. I am using the volar extension. Is there a way to resolve this so that v ...

Encountered an issue while attempting to decode the downloaded font. Parsing error from OTS in Vue

I'm facing an issue with importing a web-font into a specific component in my Vue App (built using the Vue cli webpack template). In one of my components, I attempted to import the fonts by referencing a _fonts.scss file within the project that looks ...

Tips for leveraging the power of Vuetify in Angular versions 7 and 9

I am looking to integrate Vuetify UI Components with Angular using VueCustomElement. While I have successfully integrated Angular and VueCustomElement, adding Vuetify has resulted in errors such as missing $attr and $. However, I am determined to add eithe ...

The beautiful synergy between Vuetify's v-input component and overflow animation

I am having trouble implementing an overflow animation on vuetify's v-text-field component. Despite my efforts, I can't seem to make it work as intended: <script setup> const text = 'very long long long long long text' </scri ...

Learn how to incorporate a click event with the <nuxt-img> component in Vue

I am encountering an issue in my vue-app where I need to make a <nuxt-img /> clickable. I attempted to achieve this by using the following code: <nuxt-img :src="image.src" @click="isClickable ? doSomeStuff : null" /> Howeve ...

"Utilizing Axios to convey JSON data into Vue Js: A Step-by-Step Guide

After saving my JSON data in a JS file for Vue, I encountered an issue with accessing it and getting my HTML v-for condition to work properly. The method described in the Vue.js documentation didn't help me fetch and execute the JSON data. Could someo ...

Unable to access webpack-stats.json. Please verify that webpack has created the file and the path is accurate

After setting up django with Vue, I encountered a runtime error: Error reading webpack-stats.json. Have you ensured that webpack has generated the file and the path is accurate? https://i.stack.imgur.com/jfeET.jpg Next to manage.py, the following command ...

API request was blocked due to the CORS policy

As I work on developing a web app using Vue.js, users must log in to receive an API key. My post request to the API through axios includes two parameters - a name and a password. However, upon form submission, persistent errors keep appearing: OPTIONS htt ...

What could be the reason for the issue `injection "store" not found` showing up when attempting to call `this.store.commit()`?

I am currently working on storing values with VueX, specifically using Vuex 4.0 instead of the older version 3.0. While attempting to commit a value, I encountered an issue as follows: ... this.$store.commit("changerusername", u) ... To addres ...

What is the best way to eliminate the border on Material UI's DatePicker component?

Check out this code snippet for implementing a datepicker component: import React, { Fragment, useState } from "react"; import { KeyboardDatePicker, MuiPickersUtilsProvider } from "@material-ui/pickers"; import DateFnsUtils from &qu ...