Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatePicker Not working On Ajax Loaded Content

I have stucked with this problem. The datepicker is working fine on static content.

But fails when content is loaded via Ajax.

I Have tried :-

jQuery.noConflict();
jQuery(function($) {
    $(document).ready(function(){
        $( ".datepickerRange" ).datepicker({
            dateFormat: 'dd-mm-yy',
            prevText:'',
            nextText:'',
            minDate: 0,
            maxDate: "+1M",
            showOn: "button",
            buttonImage: divadatepicker.image_url+"/calendar.jpeg",
            buttonImageOnly: true
        });
        $( ".datepicker" ).datepicker({
            dateFormat: 'dd-mm-yy',
            prevText:'',
            nextText:'',
            showOn: "button",
            buttonImage: divadatepicker.image_url+"/calendar.jpeg",
            buttonImageOnly: true,
            changeMonth: true,
            changeYear: true,
            yearRange: "1960:2015"
        });

            });

$(document).live(function(){
        $( ".datepickerRange" ).datepicker({
            dateFormat: 'dd-mm-yy',
            prevText:'',
            nextText:'',
            minDate: 0,
            maxDate: "+1M",
            showOn: "button",
            buttonImage: divadatepicker.image_url+"/calendar.jpeg",
            buttonImageOnly: true
        });
        $( ".datepicker" ).datepicker({
            dateFormat: 'dd-mm-yy',
            prevText:'',
            nextText:'',
            showOn: "button",
            buttonImage: divadatepicker.image_url+"/calendar.jpeg",
            buttonImageOnly: true,
            changeMonth: true,
            changeYear: true,
            yearRange: "1960:2015"
        });

            });

});

It is not showing the even calender small image after content loaded via ajax.

like image 661
Yaar Mallang Jeha Avatar asked Dec 27 '22 03:12

Yaar Mallang Jeha


1 Answers

Call .datepicker in your success callback function on your ajax call instead of using .live, which is deprecated. Example:

function initdatepicker(){
    $( ".datepickerRange" ).datepicker({
        dateFormat: 'dd-mm-yy',
        prevText:'',
        nextText:'',
        minDate: 0,
        maxDate: "+1M",
        showOn: "button",
        buttonImage: divadatepicker.image_url+"/calendar.jpeg",
        buttonImageOnly: true
    });
    $( ".datepicker" ).datepicker({
        dateFormat: 'dd-mm-yy',
        prevText:'',
        nextText:'',
        showOn: "button",
        buttonImage: divadatepicker.image_url+"/calendar.jpeg",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        yearRange: "1960:2015"
    });
}
$(document).ready(function(){
    initdatepicker();
});

And add this to your $.ajax success:

initdatepicker();
like image 75
Mooseman Avatar answered Dec 30 '22 09:12

Mooseman