Struggle encountered in obtaining the value of a DatePicker in VueJS

Currently, I am utilizing the vue-hotel-datepicker component for managing dates. It is functioning well; however, I am encountering an issue when attempting to retrieve the updated date value in my JavaScript code. Any advice or assistance on how to capture the date object in JS would be greatly appreciated.

Check out this link for more information.

Below you can find a snippet of my code:

VUE

<DatePicker DatePickerID="DatePickerID3" 
            :disabledDaysOfWeek="['Monday']" 
            :value="date" placeholder="RentalDays" 
            :hoveringTooltip="false"
            :endDate="new Date(2017, 9, 5)" />

JS

<script>
import Datepicker from 'vuejs-datepicker';
import HotelDatePicker from 'vue-hotel-datepicker'

export default {

    data() {
        return {
            // date:  new Date(2016, 9, 16)
            date: '',
            cdate: "",
            RentalDays: "Rent-in ► Rent-out",
            startdate:""

        }
    },
     created () {
        console.log("DATE",this.date);
    },
    components: {
        'DatePicker': HotelDatePicker,
    },
    methods: {
        getDate(date) {
            console.log("current date", date);
        }
    },
    watch: {
        value: function () {
            console.log("DATE Value");
        }
    }

}

</script>

Answer №1

For those utilizing the vue-hotel-datepicker plugin, there is a helpful list of events documented: https://github.com/krystalcampioni/vue-hotel-datepicker#events,

You have access to events such as period-selected, which provides parameters including Mouse Event, check-in date, and check-out date. Additionally, you can utilize check-in-changed and check-out-changed along with their corresponding arguments.

<HotelDatePicker
      :showPrice="true"
      priceSymbol="€"
      :periodDates="periodDates"
      @period-selected="getDates"
    />


 methods: {
        getDate(event, checkIn, checkOut) {
            console.log(date)
            console.log(checkIn);
            console.log(checkOut;
        }
    },


"When selecting a period, the provided arguments will be as follows"

// PointerEvent {isTrusted: true, pointerId: 1, width: 1, height: 1, pressure: 0, …}
// Tue Sep 21 2021 00:00:00 GMT+0200 (Central European Summer Time)
// Sat Sep 25 2021 00:00:00 GMT+0200 (Central European Summer Time)

Answer №2

Interactions between components are based on events. Whenever your datepicker triggers a dateChanged event, make sure to include v-on:dateChanged="getDate" in the element that calls your component. This way...

<DatePicker DatePickerID="DatePickerID3" 
        :disabledDaysOfWeek="['Monday']" 
        :value="date" placeholder="RentalDays" 
        :hoveringTooltip="false"
        :endDate="new Date(2017, 9,  5)" 
        v-on:dateChanged="getDate"
        />

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

Convert the MVC model into a JSON representation

My goal is pretty straightforward: I need to take an MVC model, convert it to JSON, and send it back to the server. I attempted the following code: @Html.Raw(Json.Encode(Model)); Upon inspecting the JavaScript, I noticed that the date objects in the seri ...

Is there a way to create a discord.js bot that can search for past messages without the need for a json file or storing them in a database?

Similar to the search feature in Discord. Imagine being able to enter !search [user] [query] and getting a response like "50 messages match your query." This would be like a word counting bot that doesn't need a database or local storage.The bot ...

hiding form fields using javascript

As a beginner in javascript, I am facing a challenge with a set of checkboxes in an HTML form. These checkboxes are generated dynamically from a python script. Among them, there is a checkbox labeled "N/A" that I want to hide automatically when any other c ...

Unable to identify the pdf file using multer in node.js

const multer=require('multer'); var fileStorage = multer.diskStorage({ destination:(req,file,cb)=>{ if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/jpg' || file.mimetype==='image/png') { ...

What is the most efficient way to iterate through array elements within a div element sequentially using React?

Currently, I am working with a large array of 2D arrays that represent the steps of my backtracking algorithm for solving Sudoku. My goal is to display each step in a table format, similar to animations that illustrate how backtracking works. Although I ha ...

Meta tag information from Next.js not displaying properly on social media posts

After implementing meta tags using Next.js's built-in Head component, I encountered an issue where the meta tag details were not showing when sharing my link on Facebook. Below is the code snippet I used: I included the following meta tags in my inde ...

Efficiently showcase connected pages in real-time

I've come across an issue with my express app. Whenever a navigation link (such as Home, Home1, or Home2) is clicked, an error occurs. However, if I manually type in http://localhost:8001/home1, it displays home1.html without any issues. What I' ...

Discover the process of executing two functions simultaneously by interacting with a VRbutton through React360

As a newcomer to React, I am still learning the ropes and facing a challenge with using two functions simultaneously with Vrbutton (or any button) on onClick event. I have attempted various methods (referenced in my commented out code below) to make multi ...

Utilize OpenLayer3 to showcase Markers and Popups on your map

I am currently exploring how to show markers/popups on an osm map using openlayers3. While I have come across some examples on the ol3 webpage, I'm interested in finding more examples for coding markers/popups with javascript or jquery, similar to som ...

Exploring Ramda JS for mapping a particular value from two JSON files

One challenge I'm facing involves using 2 JSON files to map out the status of an event, and I'm unsure how to execute this in Ramda. const input1 = { data: { memberId: 12345, orderStatus: pack ...

Utilizing datalist input with Formik: A step-by-step guide

Trying to implement datalist in a formik form using ReactJS. The goal is to display an array dynamically in the datalist options within the formik form. Here is what has been attempted: <Formik initialValues={initialValues} validationSchema={AddEmployee ...

How can I save the content from a tiptap editor in a PHP form?

I'm looking to integrate the TipTap editor into a PHP form as a textarea field. I've set up a Vue component and passed it to the blade view. Blade view: <form method="post" action="{{ route('dashboard.edit.postInfo', ...

An array containing various sets of Google map coordinates

I need to save the latitude and longitude coordinates of points within an object, and then store all these objects in an array. However, I am encountering an issue where each object is being added to the array multiple times. Here is the code snippet I am ...

Mastering the use of expressions in ng-click and ng-show in AngularJS

I've been working on creating expandable rows within a table, but I'm encountering some issues. Despite not receiving any error messages, the functionality isn't behaving as expected. I suspect there might be an issue with how I'm using ...

Implementing cross-app module injection in Node.js

I have two node apps/services that are currently running together: 1. the main app 2. the second app The main app is responsible for displaying all the data from different apps in the end. Currently, I have taken some code from the second app and integra ...

Checkbox selection not retained after update panel triggers

I am facing an issue with a div, id = campaignDiv, which loads its content dynamically. The content consists of checkboxes. There is an update panel that triggers every 30 seconds. The Challenge Whenever the update panel triggers, the checkboxes reset ...

Restrict the width of an absolutely positioned element to the width of its

FIDDLE I have a situation where I need to position an element absolutely, like a drop-down menu. However, when the window is resized and becomes narrow, there is not enough space for it. My requirements are: - The right edge of the dropdown should not g ...

Error encountered in Node/Express application: EJS partials used with Angular, causing Uncaught ReferenceError: angular is not defined

I seem to be missing something important here as I attempt to incorporate ejs partials into a single-page Angular app. Every time I try, I encounter an Uncaught ReferenceError: angular is not defined in my partial. It seems like using ejs partials instead ...

Converting JSON data to CSV format with JavaScript

I have been attempting to convert a JSON object to CSV using JavaScript, but the results are not as expected. UPDATE: The JSON object is stored in a variable, and every time I try to access 'list', it returns as undefined. Is there a way to acce ...

Adjust the height of an element using jQuery to dynamically match the window size without needing to refresh the page when the

I'm currently working with a script that functions properly when the page is refreshed. However, I am looking to dynamically obtain the size of the resized window without needing to refresh the page and then apply the corresponding height to a section ...