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?
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.
datepicker({ beforeShowDay: function(date) { var day = date. getDay(); return [(day != 1), '']; } }) }); This code disable all Mondays from the calender.
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.
$("#from").datepicker('disable');
should work, but you can also try this:
$( "#from" ).datepicker( "option", "disabled", true );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With