Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery Dialog Event repeat triggering
    primarykey
    data
    text
    <p>I am opening a calendar plugin in jquery dialog.</p> <p>The issue I had been facing is whenever I close the dialog and reopen back, my calendar event <code>onDayClick</code> will trigger twice. If repeat will trigger 3 times and so on.</p> <pre><code>&lt;div id="show_calendar"&gt; &lt;div class="custom-calendar-wrap"&gt; &lt;div class="custom-header clearfix"&gt; &lt;nav&gt; &lt;span id="custom-prev" class="custom-prev"&gt;&lt;/span&gt; &lt;span id="custom-next" class="custom-next"&gt;&lt;/span&gt; &lt;/nav&gt; &lt;/div&gt; &lt;div id="calendar" class="fc cw-calendar-container"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;script&gt; $(function(){ //OpenCalendar $('.open-calendar').on('click', function() { var cal = calendar_wall(); $('#show_calendar').dialog('open'); return false; }); }); $('#show_calendar').dialog({ width:'75%', height:'800', title:'Select Tour Date', autoOpen:false, modal:true , open: function(event, ui) { }, buttons: { 'Submit' : function() { $( this ).dialog( "close" ); } } }); function calendar_wall(){ var cal = $( '#calendar' ).calendarWall( { onDayClick : function( $el, dateProperties ) { console.log("A"); }); //Nav $( '#custom-next' ).unbind("click").bind("click", function() { console.log("B"); } ); $( '#custom-prev' ).unbind("click").bind("click", function() { console.log("C"); } ); return cal; } &lt;/script&gt; </code></pre> <p>Calling <code>calendar_wall()</code> outside the click event will not cause repeat triggering. But my webpage is ajax style so open calendar button will be click a lot of time which in the end become slow due stacking.</p> <p>:::::UPDATE:::::</p> <p>Ok I just found out rebind back the next and prev year button will solve the issue. What left now is the onDayClick event will still trigger repeatedly. I add up plugin code below.</p> <pre><code>$.CalendarWall.defaults = { monthNames : shortMonthName, dayNames : DayName, onDayClick : function( $el, dateProperties ) { return false; } }; $.CalendarWall.prototype = { ... ... _initEvents : function() { var self = this; //How do i add unbind and bind here?? this.$el.on( 'click.calendarWall', 'td', function() { var $cell = $( this ), idx = $cell.index(), dateProp = { day : $cell.children('span.date').text(), weekdayname : $cell.children('span.weekday').text(), month: $cell.closest('table').find('th.cw-month &gt; span.month').text(), monthname: $cell.closest('table').find('th.cw-month &gt; span.monthname').text(), year : self.year }; if( dateProp.day ) { self.options.onDayClick( $cell, dateProp ); } } ); }, } </code></pre> <p>:::: UPDATE 2 ::::</p> <p>Adding this line to the plugin event no longer have the issue.</p> <pre><code>this.$el.off('click.calendarWall').on( 'click.click.calendarWall', 'td', function() { </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload