Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 datepicker disable dates using javascript

I rewrited my question:

I'm using Kartick DatePicker to display a datepicker. On this datepicker, I want to disable dates using javascript. Here is what I have:

<?= DatePicker::widget([
    'name' => 'mydate',
          'language' => 'fr',
          'clientOptions' => [
              'autoclose' => true,
              'format' => 'dd-M-yyyy'
          ]
  ]);?>

With the JS:

 $(function(){
     $("#w0").datepicker("setDatesDisabled", ['25-08-2017']);
});

I tried to change the format of the date to 2017/08/25 or 08/25/2017 but in any case nothing is displayed into the logs.

I also tried to use kvDatepicker() instead of datepicker() but this gave me

Uncaught TypeError: $(...).kvDatepicker is not a function

Any clue on what is wrong here? Thank's.

like image 201
MHogge Avatar asked Aug 07 '17 21:08

MHogge


1 Answers

Your date is in the wrong format. It should be specified as:

$("#w0").datepicker("setDatesDisabled", ['08/25/2017']);

Of course make sure that w0 is the correct ID for the input element... it might also be that your selector doesn't match the input.

I've verified on the demo page that entering this in the browser's console correctly disables Aug 28:

$('#sandbox-container input').datepicker("setDatesDisabled", ['08/28/2017']);
like image 162
K Scandrett Avatar answered Nov 06 '22 07:11

K Scandrett