What steps do I need to follow to implement the Vuetify 3.3.4 date picker component in my project?

I am currently utilizing the latest version of vuetify 3 (3.3.4 - lab) date-picker component in my project. To do this, I have created a custom date-input component within my project's component folder.

/components/DateInput.vue

<template>
  <div>
    <v-menu
      v-model="menu"
      :close-on-content-click="false"
      :nudge-right="40"
      transition="scale-transition"
      offset-y
      min-width="290px"
    >
      <template v-slot:activator="{ props }">
        <v-text-field
          v-bind="props"
          :value="dateFormatted"
          variant="outlined"
          append-inner-icon="mdi-calendar"
          @change="onChange"
          @input="updateDate"
        ></v-text-field>
      </template>
      <v-date-picker
        :value="getDate"   
        @change="onChange"
        @input="updateDate"
      ></v-date-picker>
    </v-menu>
  </div>
</template>

<script>
export default {
  props: {
    /**
     * Date on ISO format to be edited.
     * @model
     */
    value: {
      type: String,
      default() {
        return ""
      },
    },
  },
  data() {
    return {
      menu: false,
    };
  },
  computed: {
    dateFormatted() {
      return this.input ? new Date(this.input) : "";
    },
    getDate() {
      /**
       * Return ISO 8601
       */
      let date = this.input ? new Date(this.input) : new Date();

      let month = 1 + date.getMonth();
      if (month < 10) {
        month = `0${month}`;
      }
      let day = date.getDate();
      if (day < 10) {
        day = `0${day}`;
      }
      return `${date.getFullYear()}-${month}-${day}`;
    },
  },
  methods: {
    onChange(val) {
      console.error(val)
    },
    updateDate(val) {
      this.menu = false;
      console.error(val)
    },
  },
};
</script>

/App.vue

<template>
  <v-container>
    <v-row>
      <v-col cols="6">
        <date-input></date-input>
      </v-col>  
    </v-row>
  </v-container>
  
</template>

<script>
import DateInput from './components/DateInput.vue';

export default {
  components: {
    DateInput,
  },
}
</script>

Whenever I try to select a date, I keep encountering an error similar to the one below:

https://i.sstatic.net/N7hJ8.png

Can someone point out what I might be doing wrong? To help with troubleshooting, I have deployed the project to codesandbox. Here is the link to the sandbox:

https://codesandbox.io/p/github/eguvenc/test/main

Answer №1

Looks like there was a bug in the VDatePicker component, but it has been fixed now. If you don't want to switch to the nightly build, you may have to wait for the next release.

To avoid the issue, make sure you are using the correct :modelValue property instead of :value. The :modelValue should be an array containing Date objects. Here's an example:

      <v-date-picker
        :modelValue="getDate"
        @update:modelValue="updateDate"
      ></v-date-picker>

In Vue 3, there is no longer a change event - use @input as @update:modelValue instead. Make sure your getDate function returns a Date array:

getDate() {
  const date = this.input ? new Date(this.input) : new Date()
  return [date]
}

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

content flickering due to ajax loader

Setting: My current project involves using Ajax to switch between different SVG images within an interactive map. I've managed to incorporate a loader image into the Ajax requests, but each time it triggers, the existing SVG disappears completely unt ...

Error: An issue occurred in the driver.execute_script function causing a JavascriptException. The error message indicates

When attempting to run some JavaScript code on the Chrome driver, I encountered a JavascriptException. Despite my confidence in the correctness of the JS code, the following error message was displayed: raise exception_class(message, screen, stacktrace) s ...

Retrieve the value of a dynamically generated radio input with Vue.js

I have a requirement to dynamically generate a list using v-for, which includes radio input elements. The purpose of this list is to allow patients to book appointments based on the selected slot value that is passed to a function when a radio button in th ...

Unlocking nested JSON data in React applications

Encountering an issue while retrieving a nested JSON object from a local API endpoint /user/{id}. Here is an example of the JSON object: {"userId":122,"name":"kissa","email":"<a href="/cdn-cgi/l/email-protect ...

Simple steps to change JSON Object to JavaScript array

Referring to this question and this other one, I am seeking advice on how to handle a JSON object structure different from the examples provided: This is my JSON Object: var myData = { "04c85ccab52880": { "name": "name1", "firstname": ...

Having trouble with a JQuery selector not functioning properly when trying to select a class in the HTML that contains a

Looking for help with a JQuery selector to target the title of a YouTube video. Here's the HTML snippet: <div class="ytp-title-text"> <a class="ytp-title-link yt-uix-sessionlink" tabindex="13" target="_blank" ...

An overabundance of parallax visuals

I'm currently working on a static website that features several parallax images dividing each section. However, I've run into an issue as I continue to add more sections and parallax images. Some of the images at the bottom of the website are shi ...

What is the reason for not modifying the filtered and sorted data?

I am currently working on implementing filter options for an item list, but I am facing an issue where the filtering does not work when selecting dropdown options. Array in App.jsx const cameraShowList=[ {id:1,model:"Canon",title:"Canon ...

Wondering how to go back to the default locale in Next.js?

Within my Next.js application, I have successfully implemented the next-i18next module for multi-language support. The app currently supports two languages: English and Arabic, with English set as the default. To allow users to toggle between languages, I ...

Displaying a pyramid of numbers with JavaScript

Is there a way to create a pyramid number structure in JavaScript? for (i = 1; i <= 5; i++) { var k = ' '; var myspace = ''; for (j = 0; j < i - 0; j++) { k += i; myspace += ' '; } console.log(myspace + ...

Printing a page with window.print() results in the removal of check marks from checkboxes

I have implemented a checklist feature using icheck radio buttons and checkboxes. Along with the checklist, there is also a button provided to print the checklist. <style> @media print { #printpage { display: none; } #submit { displa ...

Converting a string date format to UTC: A step-by-step guide

In my Typescript code, I am trying to convert a date/time format from string to UTC format but currently facing an issue with it. The desired output is as follows: 2018/10/27+16:00 => 20181027T01000Z import * as moment from 'moment' dates=$ ...

Is your JavaScript Array failing to index correctly?

var graphdata = [["A", "B", "C", "D"], [0.5, 0.25, 0.5, 0.25]]; function randomData (){ var labels = graphdata[0] var labels2 = graphdata[1]; console.log(); return labels.map(function(labels, labels2){ console.log(labels2); ...

Reading very large .csv files using the FileReader API in JavaScript with only HTML/jQuery can be accomplished by following these

Having trouble handling a large .csv file over 40 MB (with more than 20,000 lines) and displaying it as an HTML table. I'm developing a system using only pure HTML + JQuery. This is the format of my .csv worksheet: ================================== ...

Display the div only when the time variable reaches zero

I want to display a div when the difference between the time imported from the database and the current time is 0. How can I achieve this? Here is the code snippet: while ($row = mysqli_fetch_array($result)) { echo "<div class='alert' id= ...

A guide to duplicating an image and placing multiple copies in various random locations

I'm trying to add multiple copies of an image to my webpage using create.js. I want each copy to be placed in a random position. I attempted to use the jQuery clone() method, but it didn't work as expected. function handleComplete(e) var _ob ...

Passing retrieved REST data from service file to AngularJS controller

Hey everyone, I'm new to angular js and running into an issue with sending data from my service file to the controller, which is then supposed to be displayed in my HTML. Could someone please provide some guidance on how to solve this problem? Thank y ...

Generating an order prior to payment being made by the customer

When a user selects a product and clicks the pay button, they are redirected to Stripe where a new order is created. However, if the user changes their mind and cancels the payment during the Stripe checkout process, the order has already been created. How ...

Javascript's callback mechanism allows functions to be passed as arguments

I am currently delving into the intricacies of the callback mechanism in javascript, particularly typescript. If I have a function that expects a callback as an input argument, do I need to explicitly use a return statement to connect it with the actual ca ...

I am unable to log the response, but I can view it in Postman and the network tab

Currently, I am working on setting up a register feature with a specific endpoint. The challenge I am facing revolves around handling validation responses from the backend. For instance, if I attempt to register with a username that is less than six charac ...