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

The mathematical logic behind navigating forward and backward in Angular

Calling all math experts! I need your help with a slider issue. The prevSlide function is working perfectly, but the nextSlide function seems to be starting off on the wrong foot. It goes 1-2-3 and then jumps to 2-3-2-3... It's definitely a math probl ...

Having trouble with jQuery not loading? Learn how jquery-rails operates

Currently, I am diving into the world of jquery and ajax by watching railscasts episode 136 revise jquery & ajax. Despite putting in over 4 hours of effort, I am still unable to get past the initial hurdle. The issue seems to revolve around adding remote: ...

How do I retrieve two input values using script code in Ajax?

Currently, I am facing a challenge with implementing two input values in my database search using AJAX. While the script code works well for one input value, it performs poorly with two input values. Below, you will find the codes that I have used. Firstly ...

Tips for utilizing multiple components in Angular 2

I am a beginner in angular2 and I am attempting to utilize two components on a single page, but I keep encountering a 404 error. Here are my two .ts files: app.ts import {Component, View, bootstrap} from 'angular2/angular2'; import {events} f ...

The functionality of using variables in conjunction with the .insertAfter method appears to be

As a novice coder with limited English skills, I apologize in advance. Here is the CSS code snippet I am working with: #wrapper{ width: 200px; height: 300px; border: solid 1px #000; overflow: visible; white-space: nowrap; } .page{ ...

Making AngularJS work with angular-ui bootstrap and ensuring compatibility with IE8

Having trouble getting AngularJS code that utilizes angular-ui bootstrap to function properly in IE 8? Following the guidelines in the AngularJS developer guide on IE didn't seem to solve the issue for me. I inserted the code snippet below into my ind ...

Clearing all data in a form upon opening

Within a single portlet, I have organized two forms under separate tabs. What I am aiming for is that whenever I switch to tab 2, all fields within its associated form should automatically be cleared without the need for a button click. Even after attempti ...

Issue with displaying hamburger menu items when using data-toggle in Angular

I've been diving into learning Angular and Bootstrap lately. I wanted to merge some existing HTML content into an Angular component, but ran into issues with its functionality. When I attempt to toggle the hamburger menu icon, nothing happens, and the ...

What is the best way to search for items using only a portion of a phone number or typing a name in any case (uppercase, lowercase) and still get accurate results?

let contacts = [ { name: 'John', phone: 987654 }, { name: 'Sara', phone: 654321 } ] I am developing a contact manager app with various functions to manage contacts. Add new contac ...

Imitate a HTTP request

Currently, I am working on developing a front-end application using Angular (although not crucial to this question). I have a service set up that currently supplies hard-coded JSON data. import { Injectable } from '@angular/core'; import { Obser ...

The Vue3 property 'x' is not recognized on type 'Function' as a global property

I have encountered a strange issue with my Quasar app. I am attempting to define a global variable that consists of metadata about the application in an object format. Despite successfully compiling the app and displaying the correct information on the HTM ...

What is the best way to ensure that the input search bar, microphone icon, and two small boxes adapt to different screen

Upon submitting my exercise for The Odin Project, I was under the impression that everything looked perfectly aligned and centered on my MacBook Pro 15-inch screen. However, when I viewed the completed webpage on a larger computer screen at work, I noticed ...

Tips for finding the displayRows paragraph within the MUI table pagination, nestled between the preceding and succeeding page buttons

Incorporating a Material-UI table pagination component into my React application, I am striving to position the text that indicates the current range of rows between the two action buttons (previous and next). <TablePagination ...

Toggle the Editable Feature in AngularJS JSON Editor

Currently, I'm utilizing a library called ng-jsoneditor that is available on GitHub. I am attempting to switch the state of an element from being editable to being read-only. To indicate that an element should be read-only, I need to specify the onE ...

Revoking existing Json Web Tokens when updating user information

Once a user logs in with their username and password, they receive an access_token containing the payload that includes their uniqueTokenIdentifier. This unique identifier is stored for each user in the database. If a user changes their password due to ac ...

Employing the "div" element to target in CSS styling

I'm dealing with a document structure that is consistent across multiple pages. HTML: <ul> <li> <div> <img src="" /> </div> </li> </ul> Presently, there is a border aroun ...

Converting a string to a date in JavaScript

Is there a way to convert a string like "20150415" into a date with the format "2015, April, 15th"? I've come across multiple examples, but they all involve splitting with "-" or "/", which doesn't work for my case. Below is my current code snip ...

Unable to access an element using jquery

This is an example of an HTML file: <div id ="main"> </div> Here is the JavaScript code: //creating a new div element var divElem = $('<div class="divText"></div>'); //creating an input element inside the div var i ...

Monitor a nested watch property for potential undefined or default values

Currently tackling an issue in my Vue2 project related to a specific property I'm trying to watch. Here's what the code snippet looks like: watch: { 'car.wheels': function(){ ... } Sometimes, 'wheels' is undefined ...

This piece of code is causing my browser to lag

I am encountering an issue with fetching and adding values from a weather API to my HTML elements. My goal is to display the hourly forecast for today, starting from the current hour until midnight of the next day. In order to optimize space, I implemente ...