When using FullCalendar JS, I am trying to show both the event title and end date. However, the end date is appearing in milliseconds in the display (I assume)

I have the following AJAX code snippet for the calendar:

$.ajax({
   url: 'display_event.php',  
   dataType: 'json',
   success: function (response) {
        
   var result=response.data;
   $.each(result, function (i, item) {
       events.push({
           event_id: result[i].event_id,
           title: result[i].title,
           start: result[i].start,
           end: result[i].end,
           //color: result[i].color,
           url: result[i].url
       });  
   })
   var calendar = $('#calendar').fullCalendar({
       defaultView: 'month',
        timeZone: 'local',
       editable: true,
       selectable: true,
       selectHelper: false,
       select: function(start, end) {
               //alert(start);
               //alert(end);
               $('#event_start_date').val(moment(start).format('YYYY-MM-DD'));
               $('#event_end_date').val(moment(end).format('YYYY-MM-DD'));
               $('#event_entry_modal').modal('show');
           },
          
       events: events,
       eventRender: function(event, element, view) { 
           element.find('.fc-title').append(" <b>" + event.end +"</b>");
           element.bind('click', function() {
           
                   alert(event.end);
               });
       }
       }); //end fullCalendar block 
     },//end success block
     error: function (xhr, status) {
     alert(response.msg);
     }
   });

In my code, I have concatenated "event.end" with the event title but it is currently displayed in milliseconds. Ideally, I want it to be shown as YYYY-MM-DD based on the database and JSON data provided. The JSON data appears to be correctly passing YYYY-MM-DD format (e.g. 2023-08-13).

The current output looks like this screenshot below. My goal is to display the event as "GovernmentHoliday 2023-08-13".

enter image description here

The alert functionality, however, seems to be working fine.

element.bind('click', function() {
           
                   alert(event.end);
               });

Answer №1

When you merge the value of the Time object it will output the unix timestamp in milliseconds. If you present a Time object to prompt, its toString() function is invoked.

Keep in mind that event.end may be null for events with identical values for start and end (for example, all day event on single day). You should verify that event.end is not null before using it.

eventRender: function (event, element) {
    if (event.end !== null) {
        element.find('.fc-title').append(" <b>" + event.end.format('YYYY-MM-DD') + "</b>");
    }
}

You seem to be utilizing an older version of FullCalendar. It might be beneficial to switch to the plain JS version which eliminates the Moment and jQuery dependencies.

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 is the best way to create a paginator class that can navigate one page at a time using HTML and CSS?

I recently found the infusion theme online and you can check out some examples of it here There is also a live preview available here However, I am encountering difficulties in getting the paginator class to move. It seems like when one of those elements ...

Guide on launching a Firefox browser through Selenium 3.6.0 with a different profile in JavaScript

How can I customize the Firefox browser settings in selenium-webdriver 3.6.0 for automated testing? I need Firefox to download files without prompting and save them to a specific directory. For Google Chrome, the approach is as follows: if (this.bName == ...

How to Convert a String to JSON in Python

I have data in this specific format: "{u'Status': u'Up About an hour', u'Created': 1468874455, u'Image': u'instavote/vote', u'Labels': {u'com.docker.compose.service': u'webapp&apos ...

Textarea is limited to resizing just one specific area

I've been experiencing issues with my textareas. The problem arises when I try to have multiple textareas that need to resize on page load. It seems to work well for the first textarea, but as soon as I insert another one, only the first one responds ...

Answer processing for the reminder dialog is underway

When I send a proactive message to a user, I want to initiate a 'reminder dialog'. The dialog is displayed, but when processing the response it goes back to the main dialog. This is how I currently set up my bot: const conversationState = new C ...

What is the best way to stack col-xs-6 elements instead of having them side by side?

My form fields are currently set up using 3 col-xs-6 classes, but I'm not seeing the desired layout. I am aiming for: | col-xs-6 | | col-xs-6 | | col-xs-6 | However, what I am getting is: | col-xs-6 | col-xs-6 | | col-xs-6 | I understand that th ...

How to set a default value in AngularJS ng-model using the value from another ng-model

One of the challenges I'm facing is transferring a value set by the user in an ng-model from one form field to another ng-model as the initial value within the same form. For example, I want the ng-init value of myModel.fieldB to be the val ...

What is the method for incorporating locales into getStaticPaths in Next.js?

I am currently utilizing Strapi as a CMS and dealing with querying for slugs. My goal is to generate static pages using getStaticPaths and getStaticProps in Next.js. Since I'm working with multiple locales, I have to iterate through the locales to re ...

tips on incorporating chosen while still enabling text input

I am currently utilizing chosen to showcase a single selection from a lengthy array of choices. In addition, I am seeking the functionality to enable users to submit a choice that is not listed among the available options. This customization is specifica ...

Exploring the world of Ajax and managing cookies

I am facing an issue with setting cookies in my login form using ajax when the "remember me" checkbox is checked. Despite having code to handle this scenario, the cookies are not getting set properly. After executing var_dump($_COOKIE), I see that only the ...

Receiving an error message of ".then is not a function" while using Inquirer

I am encountering an issue with a basic function I am trying to run using Node.js and inquirer. When I attempt to execute it, the console log shows me the error message: "TypeError: inquirer.createPromptModule(...).then is not a function." Although I have ...

Loading an HTML file conditionally in an Angular 5 component

Consider a scenario in my project where I have a testDynamic component. @Component({ templateUrl: "./test-dynamic.html", // This file needs to be overriden styleUrls: ['./test-dynamic.css'] }) export class testDynamic { constructor() ...

The iPad Air 2 experiencing issues with rendering on three.js

Recently, I've transitioned to using an iPad Air 2 for work and decided to explore equirectangular panoramas. While these panoramas work perfectly on my desktop, I was excited about utilizing the device orientation features on my iPad/iPhone. However ...

What is causing the black part in the output from rasterizeHTML.drawHTML when using canvas.toDataURL?

Whenever the button is clicked, it triggers the function common_save_project(). Currently, the canvas displays correctly on the screen after the function call, but the image generated by canvas.toDataURL turns out black where rasterizeHTML.drawHTML was inv ...

employing JavaScript code for targeting classes rather than IDs

I am facing an issue with a javascript function called MyFunc() that is currently only working with id="item_for_MyFunc". Within the function, there is a var elem = document.getElementById("item_for_MyFunc"); and the HTML body contains: <body onload= ...

What is the best way to remove an object from a complex JavaScript array structure?

I'm having trouble removing an object from the array provided below. Whenever I try to delete its properties, they just turn into undefined. I have a recursive function that correctly identifies the object I want to remove. Specifically, I need to eli ...

Inquiring about utilizing res.render and invoking functions within an EJS template

Exploring node, I created a practice function in a separate file and imported it to my server.js. With express as my framework, passing the function in the res.render object with a parameter works seamlessly. app.get('/projects', (req, res) => ...

choosing between different options within Angular reactive forms

I am attempting to create a select element with one option for each item in my classes array. Here is the TypeScript file: @Component({ selector: 'app-create-deck', templateUrl: './create-deck.component.html', styleUrls: [' ...

Automatically launch a popup window specified in JavaScript

Aim:- I am trying to automatically open a radwindow from the server-side based on a specific IF condition. Snippet Used:- In the aspx page, I have defined the radwindow as follows: <telerik:RadWindowManager Skin="WBDA" ID="AssetPreviewManager" Modal= ...

The power of Angular controllers lies in their ability to facilitate two-way

Currently, I have a controller that acts as a wrapper for ui-router and manages its flow, similar to a menu bar. When a user clicks on a menu item, a function is triggered that changes the ui-router state and broadcasts an event to the inner controllers. E ...