When attempting to select dates from the picker options, the array is found to be devoid of any entries

My challenge lies in working with an array of dates retrieved from the server to determine which dates should be disabled on the datepicker.

 getStaffAvailability(){
            let x = this;
            this.$http.get(this.weeklyAvailabilityUrl + "GetAvailableDaysForStaff/" + this.entity.staffId)
                .then(function (event: any) {
                    x.staffAvailableDays = event.body;
                });
        }

Once this method executes successfully, I can observe that the staffAvailableDays array is populated with the expected values as shown in the Vue dev tools at https://i.sstatic.net/9cUpx.png

The issue arises when attempting to access this array within the disableddates method of the datepicker options - it appears empty and devoid of any values. The reason behind this inconsistency eludes me.

 export default class StaffAllocation extends Mixins<BaseCrudMixin>(BaseCrudMixin) {
        staffAvailableDays: Date[];
        datePickerOptions: any;

        @Prop(Number) eventId!: number;

        constructor() {
            this.staffAvailableDays = [];
            this.datePickerOptions = {
                disabledDate: (currentDate: Date) => {
                    return (this.staffAvailableDays.findIndex(item => { return item.getTime() == currentDate.getTime() })) == -1;
                }
            };
}

Answer №1

After analyzing your screenshot, it appears that the variable this.staffAvailableDays is currently an array of type string instead of Date. This discrepancy will likely result in an exception being thrown when calling item.getTime().

To address this issue, one possible solution is to parse the dates before assigning them:

getStaffAvailability(){
  let x = this;
  this.$http.get(this.weeklyAvailabilityUrl + "GetAvailableDaysForStaff/" + this.entity.staffId)
  .then(function (event: any) {
    x.staffAvailableDays = event.body.map(function (d) {
      return new Date(Date.parse(d));
    });
  });
}

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

disable any other active toggle in a vue component

Exploring JavaScript and how to accomplish the following tasks Snapshot The issue I am facing is that if I click on a product, and then click on settings, both are open. However, I want only the currently clicked toggle to be open. For instance, if I cl ...

Visibility of Input-properties in Angular 2

I am encountering an issue where a component parent is calling another component child with an input-property. Although the property is available in the child's template, it does not seem to be accessible within the constructor or OnInit functions. I ...

The Vue component is successfully rendering on localhost, but is not displaying on the server when using Laravel 5.4 with Passport

I attempted to configure an Oauth2.0 server using Passport within Laravel 5.4 by following the steps outlined at . I successfully set it up on my local host, but encountered issues when deploying the code to my production server. Upon accessing the applica ...

Shift the Kid Element to an Alternate Holder

Currently, I am working on a project in Angular version 10. Within this app, there is a component that can be shared and will utilize the provided content through ng-content. Typically, this content will consist of a list of items such as divs or buttons. ...

Learn how to display the date for a full week in Vue.js using the Vue-moment library, with the format example of "May 4 - 10, 2020" alongside the corresponding weekdays

I am currently working on a project that involves displaying dates and weekdays in letters. The image below shows the current output achieved with the use of a v-for loop. https://i.stack.imgur.com/WPkEA.png <div v-for="(country, index) in info" :k ...

Importing CSS properties from MUI v5 - A comprehensive guide

I'm working with several components that receive styles as props, such as: import { CSSProperties } from '@material-ui/styles/withStyles' // using mui v4 import because unsure how to import from v5 paths import { styled } from '@mui/mat ...

Variables in a Docker file specific to VueJS

I am faced with a situation where I have a configuration file located at "src/config.js" that contains the API URL: const API_URL = 'https://some-url-here.com' export default { API_URL: API_URL } In addition, there is a Dockerfile setup as f ...

The error message "TypeError: (0 , N.createContext) is not a function" indicates that

I'm currently in the process of developing a cutting-edge application using Next.js 14, TypeScript, and Telegram Open Network. However, I've hit a roadblock while attempting to incorporate the TONConnectUIProvider at the root of my app. Upon run ...

Error: Attempting to access the 'getCroppedCanvas' property of an undefined value in VueJs

I've been exploring the vue-cropperjs library, but every time I execute the code, I encounter error messages: Uncaught TypeError: Cannot read property 'getCroppedCanvas' of undefined Uncaught TypeError: Cannot read property 'replace&ap ...

Find a string that matches an element in a list

I currently have a list structured like this let array = [ { url: 'url1'}, { url: 'url2/test', children: [{url: 'url2/test/test'}, {url: 'url2/test2/test'}], { url: 'url3', children: [{url: & ...

Utilizing a React hook to render and map elements in a function

Can the hook return function be assigned to a render map in React? In this example, we have the socialAuthMethodsMap map with the onClick parameter. I tried to assign the signInWithApple function from the useFirebaseAuth hook, but it violates React's ...

"Utilize Vue.js to dynamically update choices in Drop Down 2 according to the selected option in Drop Down

My initial dropdown code (Drop Down 1) is as follows: <div class="col-md-3"> <select name="t_col" v-model="dbColumn" class="form-control" v-on:change="columnChange(dbColumn)"> <option value="source_country" selected>Source Co ...

Enhancing React with TypeScript: Best Practices for Handling Context Default Values

As I dive into learning React, TypeScript, and Context / Hooks, I have decided to create a simple Todo app to practice. However, I'm finding the process of setting up the context to be quite tedious. For instance, every time I need to make a change t ...

The HTML element <p> is not spilling over onto a new line

Having trouble with text overflow in a kanban board? I've tried various CSS styling options like overflow-wrap: break-word;, word-wrap: break-word;, and hyphens: auto;, but nothing seems to work. Here's a preview. I'm using Vue.js, but I do ...

Verify and retrieve information from the Dynamics CRM Web API with the help of Angular 2 (TypeScript)

How can one authenticate and query the Dynamics CRM Web API from a Single Page Application developed with Angular 2 (TypeScript)? Initial research indicates that: The Dynamics CRM (version 2016 or 365) instance needs to be registered as an application ...

TypeScript - Converting into individual compiled files

Currently, I am working on a project that consists of lengthy source files. While this is advantageous for imports, it poses challenges in terms of maintenance. For instance: /main/core.ts export type Foo { ... } export interface Bar { ... } export cla ...

Accessing JSON data from a database using Angular

Wondering if there is a way to effectively access and manipulate JSON data stored in a database using Angular. While researching online, I keep coming across methods for reading JSON files from the Asset Folder, which does not align with what I need. What ...

Updating Angular 1 TypeScript 1.8 Application with Webpack 2 may lead to issues with displaying views

I previously had success working on a project using Angular 1, TypeScript 1.8, and Material Design with Webpack 1 handling the build process. However, after attempting to upgrade to Webpack 2.2.1 and TypeScript 2.2.1, I encountered issues with my app&apos ...

What is the functionality of ngModel in the Angular Heroes Tour tutorial?

Hello everyone, this is my first post here. I have been diving into the Angular Tour of Heroes using Angular 6 and I think I understand how ngModel works, but there's one thing that puzzles me. How does it manage to update the data in my list when th ...

Discover the secret to instantly displaying comments after submission without refreshing the page in VueJS

Is there a way to display the comment instantly after clicking on the submit button, without having to refresh the page? Currently, the comment is saved to the database but only appears after refreshing. I'm looking for a solution or syntax that can h ...