I can't retreive dayEvents from currentday on init

Issue #56 new
René Domingue created an issue

On page load I would like to display dayEvents data for the current day. There is a way I can receive this data with the onInit callback ? The days doesn't seem to be define yet.

Comments (6)

  1. René Domingue reporter

    I've did a workaround (really ugly for now)

    $(".responsive-calendar").responsiveCalendar({
                startFromSunday: true,
                translateMonths:translateMonths,
                events: myevents,
                onInit: function(){
                    cal = this.$element.find('[data-group="days"]');
                    setTimeout(function(){
                        $(cal).find('.today').addClass('activate');
                        today = $(cal).find('.today a');
                        var thisDayEvent, key;
                        key = today.data('year')+'-'+addLeadingZero( today.data('month') )+'-'+addLeadingZero( today.data('day') );
                        thisDayEvent = myevents[key];
                        displayDate(today.data('day'), translateMonths[today.data('month')-1], today.data('year'));
                        displayEvents(thisDayEvent.dayEvents, key);
                    },250);
                },
                onActiveDayClick: function(events) {
                  var thisDayEvent, key;
                  clearForm();
                  key = $(this).data('year')+'-'+addLeadingZero( $(this).data('month') )+'-'+addLeadingZero( $(this).data('day') );
                  $('.activate').removeClass('activate');
                  $(this).parent().addClass('activate')
                  thisDayEvent = events[key];
                  displayDate($(this).data('day'), translateMonths[$(this).data('month')-1], $(this).data('year'));
                  displayEvents(thisDayEvent.dayEvents, key);
    
                  //if mobile scroll to panel date
                  if($('.isXS').is(":visible")){
                    $('html, body').animate({
                        scrollTop: $(".js-containerDates").offset().top
                    }, 1000);
                  }
                },
                onMonthChange: function(){
                    clearStuff();
                }
            });
    

    Yeah exactly I've used a little setTimeout to let the Init have the time to set all dayEvents.

  2. Lukasz Kokoszkiewicz repo owner

    Ok, I'm not developing it currently due to very low downloads to payment ratio. What I would propose here is to run displayDate nad displayEvents not in onInit callback but just after the calendar initialization.

  3. Lukasz Kokoszkiewicz repo owner

    Basically something like this:

    $(".responsive-calendar").responsiveCalendar({
                startFromSunday: true,
                translateMonths:translateMonths,
                events: myevents,
                onActiveDayClick: function(events) {
                  var thisDayEvent, key;
                  clearForm();
                  key = $(this).data('year')+'-'+addLeadingZero( $(this).data('month') )+'-'+addLeadingZero( $(this).data('day') );
                  $('.activate').removeClass('activate');
                  $(this).parent().addClass('activate')
                  thisDayEvent = events[key];
                  displayDate($(this).data('day'), translateMonths[$(this).data('month')-1], $(this).data('year'));
                  displayEvents(thisDayEvent.dayEvents, key);
    
                  //if mobile scroll to panel date
                  if($('.isXS').is(":visible")){
                    $('html, body').animate({
                        scrollTop: $(".js-containerDates").offset().top
                    }, 1000);
                  }
                },
                onMonthChange: function(){
                    clearStuff();
                }
            });
    $(cal).find('.today').addClass('activate');
                        today = $(cal).find('.today a');
                        var thisDayEvent, key;
                        key = today.data('year')+'-'+addLeadingZero( today.data('month') )+'-'+addLeadingZero( today.data('day') );
                        thisDayEvent = myevents[key];
                        displayDate(today.data('day'), translateMonths[today.data('month')-1], today.data('year'));
                        displayEvents(thisDayEvent.dayEvents, key);
    
  4. René Domingue reporter

    For now it doesn't work either... Same errors 'dayEvents' is not defined yet. A callback is needed for after the complete initialization.

  5. Log in to comment