Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to restrict jquery date picker to only current month?

I want to set the date-picker to show only the current month and user cannot move to previous months or next months.Is there any in build function for it?

like image 911
sampathpremarathna Avatar asked Jun 20 '11 10:06

sampathpremarathna


People also ask

How do I restrict dates on date picker?

You can restrict the users from selecting a date within the particular range by specifying MinDate and MaxDate properties. The default value of MinDate property is 1/1/1920 and MaxDate property is 12/31/2120 . Dates that appears outside the minimum and maximum date range will be disabled (blackout).

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 would you restrict date picker selection based on the entry in another date field?

The requirement is also to be able to use dates in the format "dd-MMM-yy". For example, in the first date field, the user selects 26-Nov-16. Then, when they click on the date picker for the second date field, the earliest date they are able to select is 26 Nov.


1 Answers

Use changeMonth:false and stepMonths:0 and it will work.

$('#calendar').datepicker({
    changeMonth: false,
    stepMonths: 0, 
    dateFormat: "mm/dd/yy",
    firstDay: 1,
}).datepicker("setDate", "+0d" );

Working fiddle: https://jsfiddle.net/scottcwilson/phkkt20e/2/

like image 98
Scott C Wilson Avatar answered Nov 16 '22 23:11

Scott C Wilson