最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - yii2 datepicker disable dates using javascript - Stack Overflow

programmeradmin5浏览0评论

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.

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.

Share Improve this question edited Aug 22, 2017 at 5:24 K Scandrett 16.5k4 gold badges42 silver badges68 bronze badges asked Aug 7, 2017 at 21:32 MHoggeMHogge 5,19620 gold badges70 silver badges110 bronze badges 3
  • you need to let us know which Datepicker plugin you are using – csminb Commented Aug 7, 2017 at 21:45
  • You are using variable unavailable before it's defined - move $(function(){...}) after function unavailable(date) {...} and rename it to unavailable(). Actually whole second section needs rewrite - you are messing up variable & function names ... – lubosdz Commented Aug 8, 2017 at 7:49
  • I ended up using disabledDates which I didn't saw before. So I do not need to call my function anymore. Could you check my update please? @csminb I'm using the datepicker from JQuery available on GitHub, do you need more info? – MHogge Commented Aug 8, 2017 at 18:42
Add a ment  | 

2 Answers 2

Reset to default 8 +50

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']);

If you are using Yii2 Specifically than this may help you

    echo '<label id = "for-trigger">Date</label>';
                echo DatePicker::widget([
                    'type' => DatePicker::TYPE_INPUT,
                    'id' => 'anyUniqueID',
                    'name' => 'date',
                    'value' => '2020-04-11',
                    'options' => ['placeholder' => 'Selectdate ...'],
                    'pluginOptions' => [
                        'format' => 'yyyy-M-dd',
                        'daysOfWeekHighlighted' => '2,3',
                        'todayHighlight' => true,
                        'datesDisabled' => ['2020-04-06', '2020-04-21']
                    ],
                    'pluginEvents' => [
                        'changeDate' => "function(e) {  
                            //something you want to do may be 
                        }"
                    ]
                ]);
发布评论

评论列表(0)

  1. 暂无评论