Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: enabling/disabling datepicker

In my php-file, I want to use the jQuery Datepicker.

When my file loads, I create the Datepicker disabled.

Then, when a special field in my php-file (it is a form) is filled, I want to enable the Datepicker.

So, initially my Datepicker looks like this:

$("#from").datepicker({     showOn: "both",     buttonImage: "calendar.gif",     buttonImageOnly: true,     buttonText: "Kalender",     showAnim: "drop",     dateFormat: "dd.mm.yy",     changeMonth: true,     changeYear: true,     showButtonPanel: true,     showWeek: true,     firstDay: 1,     dayNamesMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],     weekHeader: "KW",     disabled: true,     onClose: function(selectedDate) {         $("#to").datepicker("option", "minDate", selectedDate);     } }); 

This works just fine, no problem so far. The problem comes, when I want to disable the field.

If a special field is filled, I call $("#from").datepicker('enable');

This also works fine, BUT now I want to disable it again if the special field I mentioned it empty again.

Then I use $("#from").datepicker('disable'); and the field itself is grayed, but I can still use the field to enter values, the calender pops up and even the calender-image next to the box is clickable.

Anyone has an idea why this is the case? Am I missing something?

like image 779
Alex K. Avatar asked Aug 21 '13 07:08

Alex K.


People also ask

How to make datepicker disable in jQuery?

To disable a datepicker in jQuery UI we will be using disable() method which is discussed below: jQuery UI disable() method is used to disable the datepicker. Parameters: This method does not accept any parameters.

How to disable days in jQuery datepicker?

datepicker({ beforeShowDay: function(date) { var day = date. getDay(); return [(day != 1), '']; } }) }); This code disable all Mondays from the calender.

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.


1 Answers

$("#from").datepicker('disable'); should work, but you can also try this:

$( "#from" ).datepicker( "option", "disabled", true ); 
like image 153
omma2289 Avatar answered Sep 19 '22 21:09

omma2289