moses toh
moses toh

Reputation: 13162

How can I display datepicker when click button in vuetify?

My script like this :

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

<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 result like this : image1

it works. but I want to change that. I want the datepicker to appear when clicking a button like this : image2

How can I do it?

Upvotes: 3

Views: 7357

Answers (2)

darebucad
darebucad

Reputation: 11

You may try this solution.

<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: You may need to add attrs here <template v-slot:activator="{ on }">

Upvotes: 0

brenzy
brenzy

Reputation: 1986

In your script, replace

<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">CALL DATEPICKER</v-btn>

Upvotes: 1

Related Questions