maggieraff / jmonthcalendar

Automatically exported from code.google.com/p/jmonthcalendar
Other
0 stars 0 forks source link

When clicking a day cell the date passed to onDayLinkClick is incorrect. #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Add this to the jscript options for the calendar:
        onDayCellDblClick: function(dateIn){
            alert(dateIn.toLocaleDateString());
            return false;
        },

2.  Double click an empty date on calendar.

What is the expected output? What do you see instead?
Expected: The date of the day clicked.
Actual: The last date in the calendar

What version of the product are you using? On what operating system?
1.3.0 Beta

Please provide any additional information below.

*** POTENTIAL SOLUTION ***

This bug occurs because of variable scope.  In JMonthCalendar there is a
loop which loops between the cells to render the days.  At the start of the
loop the current date is set:
Line 297: var currentDate = _dateRange.startDate.clone().addDays(i);

Then later on the double click function is set:
var dateBox =
jQuery("<td></td>").attr(atts).append(dateLink).dblclick(function(e) {
                defaults.onDayCellDblClick(currentDate);
                e.stopPropagation();

However the date passed is the date from the loop, which is ok for
rendering elements but not ok when the actual date is clicked because it
currently uses the last value currentDate was set to, which is the last day
on the visible calendar.  To fix this the date needs to be extracted from
the element that initiated it by parsing this value:

$(this).attr('date')

Original issue reported on code.google.com by drgenejones on 19 Jul 2009 at 6:06

GoogleCodeExporter commented 9 years ago
This should be fixed now in the source, related to issue #16

Original comment by k.leneau@gmail.com on 19 Jul 2009 at 7:14

GoogleCodeExporter commented 9 years ago
I've downloaded the latest version from svn, changed Line 56 in Index.html to
alert(date.toLocaleDateString()); and it still isn't working correctly.

Original comment by kyle.mcn...@gmail.com on 30 Jul 2009 at 4:14

GoogleCodeExporter commented 9 years ago
this is because date overrides till end. so it will alert the last day rendered.

Original comment by egidi...@gmail.com on 5 Aug 2009 at 7:00

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
*** VER 1.3.1 ***
*** POTENTIAL SOLUTION ***
*** is to return element id ( $(this) ) on  function(s), pushing its 
accessibility 
to a new level ***

Line 327:
var dateLink = jQuery('<div class="DateLabel"><a href="">' + 
currentDate.getDate() +
'</a></div>').click(function(e) {
                //defaults.onDayLinkClick(currentDate.clone());//original
                defaults.onDayLinkClick($(this)); //added as solution
                e.stopPropagation();
            });

then on options:
onDayLinkClick: function(elem) { 
                    var correctdate =$(elem).parent('td').attr('date');                 
                    alert(new Date(correctdate));
                    return false ; 
                }

Original comment by egidi...@gmail.com on 5 Aug 2009 at 8:27