Learn the simple steps to duplicate events using ctrl, drag, and drop feature in FullCalendar v5 with just pure JavaScript

My goal is to incorporate CTRL + Drag & Drop functionality in FullCalendar v5 using nothing but pure JavaScript.

I delved into the topic and discovered that this feature has been discussed as a new UI feature request on the FC GitHub repository. There have been a few suggestions on how to achieve this, some of them even effective.

arshaw mentioned on Aug 19, 2015

To implement this feature, you can utilize eventDrop. The jsEvent contains a ctrlKey property that you can use for testing purposes. Copy the event parameter to a new variable, use revertFunc to revert back and then apply renderEvent with the newly created variable.

chris-verclytte commented on Apr 11, 2016 did not provide a solution that worked for me

If it can help, here is a workaround I've been using while waiting for the integration of this new feature.
In the eventDrop callback:

    // If alt key is not pressed, move the event; Otherwise duplicate it
    if (!jsEvent.altKey) {
        // Handle drag'n'drop copy
    } else {
        // Handle drag'n'drop duplication
        // Add the event to the event source
        _addEventToSelectedSource(event.start, event.end);
        // Prevent default behavior by using revertFunc to avoid moving the event
         revertFunc();
    }
The only issue with this is that the copied event disappears during drag'n'drop due to a certain function in the underlying FullCalendar codebase

The solution I personally prefer is by AllyMurray shared on Jul 13, 2018

For those facing this problem, I have developed a solution that should serve as a good starting point. It follows a similar approach to external events and does not disturb the original event.

Links for reference:
https://stackoverflow.com/a/51327702/3891834
https://codepen.io/ally-murray/full/JBdaBV/

However, I am unsure on how to implement this solution using solely pure JavaScript.

Can anyone assist? I am looking for the copy functionality to work such that pressing CTRL duplicates the event while keeping the original event in its original position.

jsFiddle link

Answer №1

element, I have devised a simple solution that effectively works. The key aspect involves duplicating the moved event at its original date if the Ctrl key is being pressed. To properly test this code snippet, it is essential to firstly click into the input field located at the top of the page before executing any tests. This step ensures that the iframe gains focus and triggers both the keydown and keyup events without any issues. Moving forward, a few workarounds were implemented to address certain challenges encountered with Fullcalendar disabling drag behavior when the Ctrl key is active. To overcome this obstacle, adjustments were made to the MouseEvent.prototype in order to consistently return false when referencing ctrlKey. For further insight, you can access the specific code snippets from the official Fullcalendar repository links provided within the text. If interested, you can explore the detailed solution through a Stackblitz demo built with TypeScript or delve into a comprehensive standalone project featuring TypeScript and Webpack integration available at the given GitHub repository link: https://github.com/Guerric-P/fullcalendar-drag-and-drop-copy.

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

Modify the selected toggle buttons' color by utilizing the MUI ThemeProvider

I am currently working on customizing the color of selected toggle buttons within my React app using TypeScript and ThemeProvider from @mui/material 5.11.13. Despite my efforts, when a toggle button is selected, it still retains the default color #1976d2, ...

Initiating an Ajax POST request when the onblur() event is triggered

Having an issue with Ajax. I'm trying to submit a changed value from an input field on the onblur() event, but there's a flicker that's bothering me. When I enter a new value and click away, the old value briefly flashes back before changi ...

What is the proper way to create a regex pattern that specifies 'without any spaces'?

I need assistance in creating a regex expression that specifies "and NO whitespaces". I have to incorporate this into the following if statement shown below: $('#postcode').blur(function(){ var postcode = $(this), val = postcode.val(); ...

Locate each document in MongoDB that pertains to a time period of

I have been trying to fetch data for the past n days. For instance, I am interested in retrieving data from the last 3 days. However, after following a solution I found on StackOverflow, I am only able to retrieve one document instead of all the documents. ...

history.js - failure to save the first page in browsing history

I have implemented the history.js library to enable backward and forward browser navigation on an AJAX products page triggered by clicking on product categories. While I have managed to get this functionality working smoothly, I am facing a particular iss ...

Once the data is retrieved and the old image is deleted, attempting to upload the new image still results in the old image being displayed in the Next.js application with React Query

async function fetchTour() { const response = await api.get(`/tour/${router.query.slug}`); return response.data; } const { data: tourData, isLoading, isFetching, isTourError: isError, } = useQuery(['fetchTour', router.que ...

Angular2 Dropdown not updating with values from API

Here is the structure of my project flow: import_product.html <div class="row custom_row"> <div class="col-md-2">Additional Duty: </div> <div class="col-md-2"> < ...

When using `setState()`, ensure that you are updating a component that is already mounted or in the process of mounting. If you receive this error, it

When using WebSocket to communicate with my server, I call the handleSubmit() function to send data and update my state based on the received response. Everything works fine initially. Upon calling componentWillUnmount, I stop sending data to the websocke ...

Retrieving the original state value after updating it with data from local storage

Incorporating the react-timer-hook package into my next.js project has allowed me to showcase a timer, as illustrated in the screenshot below: https://i.stack.imgur.com/ghkEZ.png The challenge now lies in persisting the elapsed time of this timer in loca ...

React Router Error: Hook call invalid. Remember to only use hooks inside the body of a function component

I am having an issue with my React app that uses react router. In Box.js, I am attempting to access the URL parameters but I am encountering the following error message: Invalid hook call. Hooks can only be called inside of the body of a function component ...

Animate a div component sliding out while seamlessly introducing a new one using React

For my signin page, I've set it up so that users first enter their username and then click next to trigger a fluid slide animation which reveals the password field from the right. Although the separate components are already coded and the animation wo ...

Utilize two separate functions within the onchange event of a v-checkbox component in a Vue.js application

I am currently using Vue.js with Vuetify and Laravel. In one of my components, I have a dynamic datatable that fetches data from the database using axios. Within this datatable, there are v-checkboxes. Everything is functioning as expected, but now I want ...

What is the best way to add values to a JavaScript object using jQuery or plain JavaScript?

I have an object here and I am looking to dynamically insert values into it. var mergTr={}; //object for(dd in dispID) { var dataID=displayObj[dispID[dd]]; if(dataObj[dataID]) { var flag=0; var v ...

Guidelines for executing a PHP script upon a button click

I am new to learning PHP. I have a jQuery code that I need to implement in PHP. The active class simply changes display:none to display:block. You can find the code here. $(document).ready(function(){ $(".cecutient-btn").click(function(){ event. ...

Retrieve the attributes of a class beyond the mqtt callback limitation

Currently, I am utilizing npm-mqtt to retrieve information from a different mqtt broker. My objective is to add the obtained data to the array property of a specific class/component every time a message is received. However, I'm facing an issue wher ...

Unlimited scrolling feature in Ionic using JSON endpoint

Trying to create an Ionic list using data from a JSON URL. JSON Code: [{"id":"1","firstName":"John", "lastName":"Doe"}, {"id":"2","firstName":"Anna", "lastName":"Smith"}, {"id":"3","firstName":"Peter", "lastName":"Jones"},{......................}] app.j ...

Disable Dates in Material UI Date Textfield

Is there a way to prevent users from selecting dates between the specified Min and Max dates in a material UI date textField? For example, if the minimum date is today's date 01/30/2023 and the maximum date is next month's date 02/30/2023, I wou ...

Acquire the content of an interactive website with Python without using the onclick event

I am looking to extract the content of a dynamically generated website after clicking on a specific link. The link is structured as follows: <a onclick="function(); return false" href="#">Link</a> This setup prevents me from directly accessin ...

Changing the color of a div element dynamically with JavaScript

Is there a way to improve the code below so that the background color of this div box changes instantly when clicked, without needing to click twice? function updateBackgroundColor(platz_id) { if(document.getElementById(platz_id).style.backgroundCol ...

Utilizing Google Analytics 4 in a React TypeScript Environment

Currently, there are two options available: Universal Analytics and Google Analytics 4. The reasons why I lean towards using Google Analytics 4: Universal Analytics is set to be retired on July 1, 2023, so it makes sense to start fresh with Google Analyt ...