Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable month selection in the jQuery datepicker?

I am trying disable the left/right buttons that allow the user to change months. I've removed the drop down list of months but can't get rid of the buttons.

$("#date").datepicker({
    changeMonth: false,
    changeYear: false,
    dateFormat: 'dd/mm/yy',
    duration: 'fast'
});
like image 560
Jammer Avatar asked Aug 17 '10 11:08

Jammer


People also ask

How do I disable date range picker?

DateRangePicker can be inactivated on a page, by setting enabled value as false that will disable the component completely from all the user interactions including in form post.

How can I hide DatePicker after selecting date in jQuery?

Syntax: $(". selector"). datepicker("hide");

How do you only show time in DatePicker?

In the Data type Format dialog box, do one of the following: To format the control to show the date only, select the display style that you want in the Display the date like this list. To format the control to show the time only, select the display style that you want in the Display the time like this list.


1 Answers

You can effectively disable them using stepMonths by making them go nowhere when clicked, like this:

$("#date").datepicker({
  changeMonth: false,
  changeYear: false,
  dateFormat: 'dd/mm/yy',
  duration: 'fast',
  stepMonths: 0
});

You can give it a try here

Or, you could remove the buttons like this:

$("#date").datepicker({
  changeMonth: false,
  changeYear: false,
  dateFormat: 'dd/mm/yy',
  duration: 'fast'
}).focus(function() {
  $(".ui-datepicker-prev, .ui-datepicker-next").remove();
});​

You can give that a try here, this works because the default showOn option is focus, if you're using a different event, just bind to that after the .datepicker() call (so its event runs first, you can't hide what isn't created yet).

like image 197
Nick Craver Avatar answered Oct 15 '22 14:10

Nick Craver