The method date.getDate() is not defined. (The expression 'date.getDate()' returns undefined) This issue is related to using FullCalendar in an Ionic 3 project

Currently, I am working on an Ionic 3 project where I have integrated a FullCalendar plugin to display a calendar UI. However, I encountered an issue while trying to change the background color of a specific day on the calendar within the page module. To address this problem, I utilized the dayRender function provided by FullCalendar.

$('#calendar').fullCalendar({

            dayRender: function (date, cell) {
              var today = new Date('2017-09-11T00:40Z')
              if (date.getDate() == today.getFullYear()) {
                  this.cell.css("background-color", "red");
              }
            },
});

Upon running the code, I received the following runtime error:

'date.getDate()' is not a function. Within the context of 'date.getDate()', 'date.getDate()' is undefined in FullCalendar for Ionic 3.

I find this perplexing as the variable 'date' should be recognized as a Date object which is already defined in the FullCalendar library.

Can anyone provide any potential solutions?

Note: Excuse my poor English proficiency.

Answer №1

The explanation provided in the dayRender callback documentation on this website https://fullcalendar.io/docs/v3/dayRender states

date represents the specific day as a Moment object.

Therefore, in your code, date is a momentJS object, not a Date object. This explains why the getDate method is unavailable for use. It would be more appropriate to also define today as a momentJS object so you can directly compare them:

$('#calendar').fullCalendar({
  dayRender: function (date, cell) {
    var today = moment('2017-09-11T00:00Z');
    if (date.isSame(today, "day")) {
      cell.css("background-color", "red");
    }
  },
  //...
});

For further information on the code snippet I've shared, please refer to http://momentjs.com/docs/#/parsing/string/ for parsing details supported by the moment constructor, and http://momentjs.com/docs/#/query/is-same/ for information on date comparison method.

You can view a live demonstration of the given example here: http://jsfiddle.net/sbxpv25p/22/

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

utilizing javascript to compare the data in a gridview with the value entered in a

I am looking to compare the values entered in my textbox with the existing values in a gridview. I have achieved this on the server side using the following function: protected void isRecordAlreadyExist(TextBox txt_Value, int res) { ds_main = new Data ...

Using Typescript to import a JSON file

Having trouble importing a JSON file into a typescript file using the import statement. I keep receiving the following error message: Error: C:\Users\Treycos\Documents\Personal\Web extensions\LocalTube\src\backgro ...

Trimming content within an editable div in JavaScript: A guide

I am working on an editable div feature where users can input text for comments. My goal is to eliminate any unnecessary spaces before and after the text. For example, if a user types: "  Hello world  &nbsp ...

Contrast the equality of two arrays with objects

I have two different types of data structures var dataA = [ { "Employee Name": "Mr. X", id: "1" }, { "Employee Name": "Mr. Y", id: "2" }, { "Employee Name": "Mr. Z", id: "3" } ]; var dataB = [ { id: "1", " ...

Provide the remaining arguments in a specific callback function in TypeScript while abiding by strict mode regulations

In my code, I have a function A that accepts another function as an argument. Within function A, I aim to run the given function with one specific parameter and the remaining parameters from the given function. Here's an example: function t(g: number, ...

Observing an item with a numerical identifier in Vue

Is there a method to monitor a specific value within an object that uses a numeric key in Vue2? If the key were a standard string like obj = {keyName: []}, I am aware that you can achieve this by: watch: { 'obj.keyName'() { //Handle arra ...

What is the best way to refresh a page after rotating the web page?

Struggling with a challenge in Next JS - can't seem to figure out how to automatically refresh the page when it rotates const app () => { useEffect(()=>{ window.addEventListener("orientationchange", function() { window.locati ...

The functionality of Ionic 3 native plugins suddenly ceased to function. After attempting to add ngx at the end, the red line error disappeared. However, the plugin still

import { Market } from '@ionic-native/market/ngx'; constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private market: Market ) { this.initializeApp(); this.m ...

Encountering issues with adding/updating meta tags in angular5

Here’s the code I’m using to dynamically add or update meta tags in Angular 5: import { Title ,Meta} from '@angular/platform-browser'; constructor( private meta:Meta) { this.meta.addTags([ {name: 'description', conte ...

Is it possible to compile all the hidden and exposed posts into a single page?

My current javascript code successfully hides and reveals a sign-up form on my website, but I am facing difficulties when trying to implement the same functionality for multiple forms on a single page. <script type="text/javascript"> jQuery ...

Stop all file uploads using jQuery

I have integrated the jQuery File Upload plugin () into my website for image uploads. Here is my code snippet: $('#fileupload').fileupload({ url: 'server/index.php', dataType: 'json', dropZone: $('#dropzone&a ...

Locate the presence of a specific key within a JSON object

"questions": [{ "_id": "5b2bc4f6f1dacd2b0ca65bca", "updatedAt": "2018-06-21T15:32:06.237Z", "createdAt": "2018-06-21T15:32:06.237Z", "title": "What is the meaning of RC?", "answer": "opt4", "testId": "5b2bbcc ...

Error encountered: "Jest error - TypeError: Unable to access property 'preventDefault' because it is undefined."

I encountered an issue while testing the function below, resulting in the error mentioned above. function toggleRecovery = e => { e.preventDefault() this.setState( { recovery: !this.state.recovery }, () => { ...

Can you display a simple HTML view?

I am currently working on a Node.js application with Express framework. In my project, I have a 'views' folder containing an 'index.html' file. However, upon trying to load the webpage, I encountered the following error: Error: Cannot f ...

Using Ajax Uploader multiple times in a single page

I created a custom ajax file uploader that functions perfectly with one instance on the page. However, I am currently facing an issue while trying to modify it to support multiple instances. When I attempt to upload multiple files using one form, the first ...

Sending data from a controller to a resource factory in AngularJS to query the database

Problem Statement I am facing an issue with passing a variable from the view to the Angular resource factory, which is then sent to the server controller in order to determine the model that should be retrieved by the client controller. The variable issu ...

Is it possible to remove multiple keysets from Maps using Javascript?

Hi, I'm working on a map that contains key-value pairs. How can I remove multiple keysets from my map? Here is the part where the map is created: // The result key looks something like 0-119, 0-110, 0-118 for each entry this.OptionsMap.set('&apo ...

Ajax versus embedding data directly into the HTML code

Currently, my project involves a combination of JavaScript with jQuery and communication with a Django backend. Some aspects of the user interface require Ajax due to the fact that data to be sent is dependent on user input. On the other hand, there is c ...

I'm currently in the process of creating a Firefox extension and my goal is to accurately count the total number of text boxes on a webpage while excluding any hidden text boxes. Can someone please

As I work on creating a Firefox extension, I am faced with the task of counting the total number of visible text boxes on a webpage while ignoring any hidden ones. Many webpages contain hidden text fields for future use, so my goal is to exclude these fr ...

The concept of "HTML paragraph shifting"

I am looking to implement a feature similar to paragraph sliding, but I am struggling to explain it clearly. For demonstration purposes, I have added it to my website for you to view. Please note that it may take some time to load. The paragraphs slide s ...