Datepicker selected dates in the previous month

I want to show the dates of the previous and next months on my datePicker. Similar:

enter image description here

These dates should also be selected. Is there an option in jQuery default datePicker or can I change the DatePicker to look like this?

+5
source share
2 answers

This should do it:

<script>
    $(function() {
        $( "#datepicker" ).datepicker({
            showOtherMonths: true,
            selectOtherMonths: true
        });
    });
    </script>

check out: http://jsfiddle.net/fLveY/2/

+24
source

As isJustMe mentioned, this is just a way to do this. Heres a version with a little addon, which I find quite useful. If you click on the days of the next or previous month, the datepicker function will automatically switch to this month:

jQuery( '#datepicker' ).datepicker( {

    showOtherMonths: true,
    selectOtherMonths: true,

    onSelect: function( string, element ) {

        // Change month on click on other days

        var day  = element.selectedDay;
        var mon  = element.selectedMonth;
        var year = element.selectedYear;

        var target = jQuery( element.dpDiv ).find( '[data-year="'+year+'"][data-month="'+mon+'"]' ).filter( function() {

            return jQuery(this).text().trim() == day;

        } );

        if( target.hasClass( 'ui-datepicker-other-month' ) ) {

            if( parseInt( target.text().trim() ) > 15 ) {

                jQuery( element.dpDiv ).find( '.ui-datepicker-prev' ).click();

            } else {

                jQuery( element.dpDiv ).find( '.ui-datepicker-next' ).click();

            }

        }



    },

} );

adeneo .

0

All Articles