Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ui datepicker next and previous year

On the standard jquery.ui.datepicker widget there's only a next and previous button for selecting a month. If I enable year, it will be displayed in a select box.

What would be a good way to implement two buttons on both sides of the calendar? One for selecting next month and one for selecting next year, displayed next to each other on the right side, and do the same for the previous buttons on the left side of course.

$(function() {
  $("#dp").datepicker({changeYear: true});
})
like image 746
BoboProg Avatar asked Jul 02 '10 10:07

BoboProg


People also ask

How can change date format in jQuery ui Datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How to use jQuery ui datepicker?

The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.

How can I get current date in Datepicker?

You can set the current date value in DateTimePickerAdv by disabling the IsNullDate property and set the DateTimePickerAdv value as current date.


2 Answers

The best solution I have found is to combine Leniel's answer with some other properties, here is the code I have for my date elements

jQuery(document).ready(function(){
    jQuery('input.date').each(function(){
        jQuery(this).datepicker({dateFormat:'dd/mm/yy', changeMonth: true,    stepMonths: 12, showAnim:"slideDown" });
        jQuery('#ui-datepicker-div .ui-helper-hidden-accessible').css("position", "absolute !important");
        jQuery('#ui-datepicker-div').css('clip', 'auto');
    });

Hope this helps someone else as much as it did me!

P.S. The other stuff is so that the datepicker works in all browsers (ie6+,ff3+,chrome4+,safari,opera)

like image 113
MrMesees Avatar answered Sep 19 '22 06:09

MrMesees


If you just wanted to replace the current behavior of the Next and Previous buttons so that when clicking them you'd go to another year, you can use the StepMonths option:

$( ".selector" ).datepicker({ stepMonths: 12 });
like image 38
Leniel Maccaferri Avatar answered Sep 23 '22 06:09

Leniel Maccaferri