Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add buttons to a jQuery datepicker in the button panel?

Tags:

Do I just append the element to the panel wrapper and call .button()?

like image 260
Walter Avatar asked Jan 04 '11 21:01

Walter


People also ask

How can add date picker in jQuery?

$(function() { $("input#date_due"). datepicker(); }); The selector you want is all elements with the tag name "input" and the id attribute set to "date_due".

How do I change the pop up position of the jQuery datepicker control?

To change the position of the jQuery UI Datepicker just modify . ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size.

How do you use a 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.

What is datepicker format?

By default, the date format of the jQuery UI Datepicker is the US format mm/dd/yy, but we can set it to a custom display format, eg: for European dates dd-mm-yyyy and so on. The solution is to use the date picker dateFormat option.


1 Answers

If you want to keep the "clear" button while scrolling through the months, use onChangeMonthYear:.

An example:

$( "#datepicker" ).datepicker({     showButtonPanel: true,     beforeShow: function( input ) {         setTimeout(function() {             var buttonPane = $( input )                 .datepicker( "widget" )                 .find( ".ui-datepicker-buttonpane" );              $( "<button>", {                 text: "Clear",                 click: function() {                 //Code to clear your date field (text box, read only field etc.) I had to remove the line below and add custom code here                     $.datepicker._clearDate( input );                 }             }).appendTo( buttonPane ).addClass("ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all");         }, 1 );     },     onChangeMonthYear: function( year, month, instance ) {         setTimeout(function() {             var buttonPane = $( instance )                 .datepicker( "widget" )                 .find( ".ui-datepicker-buttonpane" );              $( "<button>", {                 text: "Clear",                 click: function() {                 //Code to clear your date field (text box, read only field etc.) I had to remove the line below and add custom code here                     $.datepicker._clearDate( instance.input );                 }             }).appendTo( buttonPane ).addClass("ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all");         }, 1 );     } }); 
like image 146
Rachel Avatar answered Mar 03 '23 11:03

Rachel