Search code examples
javascriptjqueryarraysuidatepickerjquerydatetimepicker

daySettings[2].replace is not a function jquery date picker


I am getting error with jquery version:

<script src="js/Common/jquery-2.1.1.min.js" type="text/javascript"></script>
 <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>

My code is :

var storedData = '["08/11/2016","07/31/2016"]';

        if( storedData !== null){
       var eventDatesarray = JSON.parse(storedData);
        var eventDates = [];

        $.each(eventDatesarray, function( index, value ) {
        var newdatepush = new Date(value);
        eventDates.push(newdatepush);
        eventDates[newdatepush] = newdatepush;
        });
        // An array of dates

        // datepicker
        jQuery('#ScheduleNextVisitCal').datepicker({
            beforeShowDay: function( date ) {
                var highlight = eventDates[date];
                if(highlight) {
                     return [true, "event", highlight];
                } else {
                     return [true, '', ''];
                }
             }
        });

}
else 
{
  $( function() {
    $("#ScheduleNextVisitCal" ).datepicker();
    });

      }

Problem statement :

i want to highlight specific date which i will get in "storedData" via jquery datepicker.

Surprise factor : //ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js //ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js

if i am using these libs then my code work fine but somehow i can not change the libs

Error name : daySettings[2].replace is not a function

issue code : http://codepen.io/srawal/pen/KrBkVG

same code with different libs working fine : http://codepen.io/srawal/pen/grjoAx


Solution

  • eventDates[ new Date( '09/04/2016' )] = new Date( '09/04/2016' ).toString(); eventDates[ new Date( '09/06/2016' )] = new Date( '09/06/2016' ).toString(); eventDates[ new Date( '09/20/2016' )] = new Date( '09/20/2016' ).toString(); eventDates[ new Date( '09/25/2016' )] = new Date( '09/25/2016' ).toString();

    This works. Don't pass date into the array. It expects a string. Convert the date into string before putting it in the array. It works.