Issue with disabled dates not refreshing in the view after adding them via button click

I have been utilizing the vue-hotel-date-picker plugin and it's been functioning well. The problem arises when I use the disabled dates props; it disables the dates initially when initializing and updating on the calendar. However, when I update the disabled dates array on any button click event, it updates the array but does not reflect or render in the view component. I have attempted to debug it using the Vue.js Chrome extension.

Here is an image from the debugging process https://i.sstatic.net/zgIu0.png

Plugin link

Below is my HTML Code

<div class="box">
    <h3>Check in only on Saturday and minimum stay of 10 days</h3>
    <DatePicker
      DatePickerID="01"
      :disabledDates = "disabledDates"
      :enableCheckout="true"
      :minNights="10"
      :useDummyInputs="false"
       placeholder="StartDate ► EndDate"
      />
  </div>
  <button @click="onChangeDisableDates()" > Change Disable Dates </button>

JS

<script>
import DatePicker from 'components/HotelDatePicker.vue';

export default {
    components: {
        DatePicker
    },

    data () {
      return {
         disabledDates : ['2017-08-18']
      }
    },
    methods : {
      onChangeDisableDates () {
         this.disabledDates.push("2017-08-19");
      }
    }
};

</script>

I am uncertain how to identify and resolve this issue; it could potentially be a problem with the plugin itself. Any assistance would be greatly appreciated!

Answer №1

Utilize the computed property: { } to ensure automatic updates whenever changes occur.

import DatePicker from 'components/HotelDatePicker.vue';

export default {
  components: {
    DatePicker
  },
  data() {
    newDisabledDates: null
  }
  computed: {
    disabledDates() {
      // Add code for disabling dates or retrieve from another variable
      if (this.newDisabledDates === null) {
        // Default implementation
        return {
          disabledDates: ['2017-08-18']
        }
      } else {
        // Updated newDisabledDates after button click
        return {
          disabledDates: this.newDisabledDates
        }
      }
    }
  },
  methods: {
    onChangeDisableDates() {
      this.newDisabledDates.push("2017-08-19");
    }
  }
};

Answer №2

function checkDisabledDates(date) {
   var day = date.getDate(); 
   var month = date.getMonth(); 
   var year = date.getFullYear();
   
   for(var i = 0; i < this.disabled.length; i++) {
      var disabledDate = this.disabled[i].split("-");
      
      if(day == parseInt(disabledDate[2]) && month == parseInt(disabledDate[1]) && year == parseInt(disabledDate[0])) { 
          return true;
      } else {
          return false;
      }
   }
}

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

What's preventing the mobx @computed value from being used?

Issue: The computed value is not updating accordingly when the observable it is referencing goes through a change. import {observable,computed,action} from 'mobx'; export default class anObject { // THESE WRITTEN CHARACTERISTICS ARE COMPUL ...

Attempting to increase a variable by 1, only to find that it appears to be doubling on its own

As I work on developing a quiz, I encounter an issue with my code. When I click on the question_holder div, variable x seems to be doubling instead of incrementing as expected. The value of x is supposed to increase by one each time, but it appears to ski ...

Using Ruby on Rails to incorporate AJAX for posting and commenting functionality

Could use some assistance with implementing AJAX into my project. It seems like it should be a simple task, but I've been struggling with it for days. My goal is to have new comments appear without the need to reload the page. Below are references to ...

Vue 3 has a known issue where scoped styles do not get applied correctly within the content of a <slot> element

Utilizing the Oruga and Storybook libraries for creating Vue 3 components. The code in the Vue file looks like this: <template> <o-radio v-bind="$props" v-model="model"> <slot /> </o-radio> </template ...

The callback function is not being executed in the Ajax request

$(document).ready(function(){ var requestURL = 'http://www.football-data.org/soccerseasons?callback=?'; $.ajax({ type: 'GET', dataType: 'json', url: requestURL, success: function(data){ cons ...

Challenges with HTML and JavaScript

Struggling to get this code to work properly with Node.js. const express = require('express') const app = express() app.use(express.static('public')) //includes content of public folder app.get('/', function (req, res){ ...

Listen for a click event on an Unordered List using addEventListener

Struggling to transform a for loop that iterates through an unordered list of hyperlinks and adds an 'onclick' function to each into one using an event listener instead. Unfortunately, I have not been able to create a functional solution. Below ...

Utilizing Three.js to showcase large 3D images from a JSON file

I am in need of showcasing 3D images. I have a .obj file that is 80 MB in size which I converted to a json file size of nearly 75 MB. While using three js, I managed to display a rotating 3D image, but the main issue is the loading speed, which currently t ...

Map on leaflet with popup next to key

I am facing a scenario where I have a map with a unique legend that is styled either as an SVG or a PNG. The legend is always positioned in the bottom left corner but can be quite large, as users have the option to toggle it on and off. Additionally, the ...

Discover the power of JQuery Mobile for implementing swipe functionality exclusively

Dealing with the jquery mobile pack has caused some major headaches for me. It completely disrupted my page by automatically turning links into ajax calls and displaying loading animations. After spending a significant amount of time trying to fix everythi ...

Restrict HTML Content in Json Result using PHP and Jquery

I'm currently working with a Controller that outputs JSON response and a JavaScript function that appends that response to the last tr in an HTML table. <pre> $reponse="<tr class=\"border_bottom\"><td>My Repo ...

Getting just the outer edges of intricate BufferGeometry in Three.js

Currently, I am immersed in a project that involves zone creation and collision detection using Three.js. The primary objective is for my application to effectively manage collisions and produce a BufferGeometry as the final output. My aim is to visually r ...

Attempting to create a login and registration form

Hello, I am attempting to create a form that can generate new user accounts and passwords. These values should be stored from the input tag when the user clicks on the register button. Unfortunately, I am encountering an issue where clicking the register ...

Executing a Function Following the Completion of getAuth() in React Firebase

I have a function that needs the user id to run properly. However, the function is executing before the getAuth process is completed. const user = getAuth() getDoc(doc(db, 'users', user.currentUser.uid)) When I try to run the above code, it thro ...

Chronological Overview (Highcharts)

Can you customize a timeline in Highcharts to resemble the image? https://i.sstatic.net/5Lipu.png I have a functional example of the timeline I desire, but the color coding and filtering aspects are challenging for me. I am attempting to apply a filter th ...

including a collection of values into a JSON data structure

Currently, I am iterating through some JSON data (grouped tweets from Twitter) to tally the frequency of specific keywords (hashtags) in order to generate an organized list of common terms. this (19) that (9) hat (3) I have achieved this by initial ...

Exploring the Power of JQuery with Hover Effects and SlideToggle

I was struggling to keep the navbar displaying without it continuously toggling when my pointer hovered over it. I just wanted it to stay visible until I moved my pointer away. <script> $(document).ready(function(){ $(".menu-trigger").hover(funct ...

"The Node.js program is unable to access the contents of the browser.js file when loaded in

After spending an unreasonable amount of time trying to debug this issue, I am still unable to resolve it. Currently, I am following a udemy tutorial where the instructor implements the same code provided below. However, despite my efforts, the code is not ...

Struggling to integrate Parse-server with vue.js

Struggling with setting up a project that incorporates parse-server in a Vuetify 3 project. Here are the steps to follow: To get started, install Parse by running npm install parse @types/parse. Create a file called parse.ts for configuration and initiali ...

Using Javascript to create session-specific cookies

Is it possible to create session-only cookies using JavaScript that get removed when the browser is closed? Due to limitations, the website I am working on is HTML-only, so server-side scripts cannot be utilized. I came across a method mentioned here: b ...