Repeatedly triggering the Jquery Dialog Event

When I open a calendar plugin in jquery dialog, I encounter a recurring issue. Every time I close and reopen the dialog, my calendar event onDayClick triggers multiple times – twice, thrice, and so on.

<div id="show_calendar">
    <div class="custom-calendar-wrap" ... </div>
</div>

...

<script>
$(function(){
    //OpenCalendar
    $('.open-calendar').on('click', function() {
        var cal = calendar_wall();
        $('#show_calendar').dialog('open');

        return false;
    });
});
...
</script>

Calling calendar_wall() outside the click event prevents repeated triggering. However, since my webpage functions with AJAX, the open calendar button may be clicked multiple times, causing performance issues due to stacking.

:::::UPDATE:::::

I discovered that rebinding the next and previous year buttons resolves the issue. The only remaining problem is that the onDayClick event still triggers repeatedly. See the plugin code below for reference.

$.CalendarWall.defaults = {
            monthNames : shortMonthName,
            dayNames  : DayName,
            onDayClick : function( $el, dateProperties ) { return false; }
};

$.CalendarWall.prototype = {    
...
...

:::: UPDATE 2 ::::

By adding the following line to the plugin event, the issue of repetitive triggers no longer persists.

this.$el.off('click.calendarWall').on( 'click.click.calendarWall', 'td', function() {

Answer №1

When you click on the open-calendar element, the function calendar_wall gets called each time and adds a new click handler to it. This leads to multiple click handlers being registered with each click.

To avoid this issue, you can implement a solution where you check if the calendar_wall function has already been called for the current instance of #calendar. If it has, then there is no need to do anything.


function calendar_wall() {
    var $calendar = $('#calendar');
    if ($calendar.data('calendar_wall')) {
        return;
    }

    $calendar.data('calendar_wall', true)
    var cal = $calendar.calendarWall({
        onDayClick: function ($el, dateProperties) {
            console.log("A");
        }
    });
    //Nav
    $('#custom-next').on('click', function () {
        console.log("B");
    });
    $('#custom-prev').on('click', function () {
        console.log("C");
    });

    return cal;
}

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

"Implementing an Ajax request to loop through a JSON

I have received these results and now I want to display them in my view: val: {email: Array(1), first_name: Array(1)} email: Array(1) 0: "The email field is required." length: 1 __proto__: Array(0) first_name: Arra ...

Electron.js issue: ipcRenderer and ipcMain leading to a white screen problem

I am currently working on a desktop application using Electron, Vue, and Vuetify. However, I have encountered an issue where sending data from the rendererProcess to mainProcess using IPC results in a white blank screen. I'm unsure of what is causing ...

Incorporating an external SVG link into a React application

While I may not be an SVG expert, I haven't encountered any issues with loading SVGs in my React app so far. I prefer using the svg tag over the image tag because sizing tends to present problems with the latter option when working with external links ...

Personalized FullCalendar header title

Is there a way to display a unique header title for each calendar in my collection of 16? I've been trying various modifications to the code snippet below with no success: firstDay: <?php echo $iFirstDay; ?>, header: { left: 'prev,next ...

Find a way to incorporate social media features into a web application that functions intermittently

Currently, I am in the process of developing a social media app and working on integrating a search feature to enable users to find friends. The code I have below seems to be functional at times but not consistent (quite frustrating!) The issue seems to st ...

Formulate a multi-line string using a collection in React's JavaScript framework

I'm working on a React function that involves a set and I need to update an HTML element using the data from this set. Below is an example of my code: const updateElement = (mySet) => { document.getElementById('myId').innerHTML = Arra ...

Cross-Origin Resource Sharing (CORS) for enabling the remote inclusion of JavaScript

I have a unique javascript widget that is designed to be embedded from an external server (e.g. ) The javascript, which contains a simple alert('hello'), is generated by a php script. Upon execution, I include a header like this: <?php heade ...

Problem: Repeated attempts to open the popup are unsuccessful

Developed a leaflet map featuring markers that open popups when clicked. Also integrated a search bar for marker searchability. However, encountering an issue where each popup can only be opened once and on selecting a marker name, the zoom functionality w ...

I am having trouble grasping certain syntax in JavaScript when it comes to using `${method_name}`

I'm having trouble understanding some of the syntax in this code, particularly ${method_name}. I'm not sure what we are achieving by passing the method name within curly braces. global._jsname.prototype.createEELayer = function (ftRule) { if ...

TypeScript - Indexable Type

Here is an explanation of some interesting syntax examples: interface StringArray { [index: number]: string; } This code snippet defines a type called StringArray, specifying that when the array is indexed with a number, it will return a string. For e ...

Is it Possible to Ajaxify a Forum Using a Bookmarklet?

My coding knowledge is limited to HTML. However, I am curious about the possibility of creating a bookmarklet that could ajaxify a forum, automatically refreshing and adding new posts to the page. Is such a thing possible? It's frustrating having to ...

What is the best method to retrieve duplicate fields from a database in HTML5?

this.db.transaction(function (tx) { tx.executeSql('SELECT tsk.*, cont.firstName, cont.lastName ,cont1.firstName, cont1.lastName, list.listId FROM tbl_tasks tsk, tbl_contacts cont,tbl_contactequests cont1, tbl_lists list WHE ...

What is the best way to add table pagination at the bottom of a table?

Can someone provide guidance on implementing table pagination for the material-ui table below? The documentation is a bit unclear: <Table ria-label="a dense table"> <TableHead> <TableRow> ...

What is the most efficient way to use map-reduce in TypeScript to filter a list based on the maximum value of an attribute?

Recently, I came across a list that looked something like this: let scores = [{name: "A", skills: 50, result: 80}, {name: "B", skills: 40, result: 90}, {name: "C", skills: 60, result: 60}, {name: "D", skills: 60, ...

Guide on properly documenting custom function types in JSDoc or TypeScript to ensure accurate referencing for VSCode IntelliSense functionality

I am currently working on documenting custom function types within an object and would greatly appreciate any assistance: A Closer Look at the Issue Consider this basic object declaration with several function properties (addCoordinate, addCoordinateOne, ...

Managing State in a React Drawer Interface

One day, I decided to create a page with a Sidebar on the left, an Appbar at the top, and a content area. Initially, everything functioned seamlessly as one enormous component. However, as we all know, React's charm lies in breaking down various eleme ...

Creating line breaks in Bootstrap input group formatting

My issue involves rows with checkboxes and labels, some of which are longer than others. When the browser is resized or viewed on a mobile device, the columns containing longer labels collapse to a second row while shorter labels stay beside their checkbox ...

"Exploring the power of asynchronous programming with dynamic async await in

I am currently working on creating a versatile function that can dynamically call async functions. //passing the controller and functionName (string) function asyncAwaitCaller(controller, functionName) { let result = await controller[functionName]; } ...

Enable Class exclusively on upward scrolling on the browser

Is there a way to dynamically change the class of an element only when the user scrolls the browser page upwards? Issue Filide>> JavaScript $(window).scroll(function() { var scroll = $(window).scrollTop(); if (scroll <= 100) { $( ...

Is Eval really as bad as they say... What alternative should I consider using instead?

After making an ajax request, a JSON array filled with user inputs is returned to me. The inputs have already been sanitized, and by utilizing the eval() function, I can easily generate my JavaScript object and update the page... However, there lies a dil ...