19

I want to use yii2 datepicker but I'm having trouble to implement this. It does not show the date picker and I don't know what is missing in my code. I'm still new in this yii

<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

?>

<div class="row">
    <div class="col-lg-6">

<div class="myproj-index">

    <?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?>
        <? //$form->field($model, 'periodfrom')
           echo DatePicker::widget([
               'model' => $model,
               'attribute' => 'periodfrom',
               'language' => 'en',
               'dateFormat' => 'yyyy-MM-dd',
           ]);
        ?>

        <div class="form-group">
            <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
        </div>
    <?php ActiveForm::end(); ?>

</div>
</div>
</div>

Edit

I downloaded this file here jui

I found out that in my file I have no jui folder under yiisoft folder. My question in appasset how can I declare this files ?

Answer

I fixed it, I downloaded the jquery-ui files then added them to the bower folder in yii2.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ashTon
  • 1,101
  • 4
  • 14
  • 23
  • To render with proper labels use field($model, 'date_created')->widget(DatePicker::className(),['clientOptions' => ['periodfrom' => '1980-01-01'],'dateFormat' => 'yyyy-MM-dd']) ?> – crafter Nov 03 '15 at 16:46
  • Just curious, how to load the datepicker inline? – shasi kanth Dec 15 '16 at 15:40

3 Answers3

18

First install this extension through composer.

  1. run: php composer.phar require --prefer-dist yiisoft/yii2-jui "*" in your project directory.
  2. update composer.
  3. In your view file use use yii\jui\DatePicker;.

You probably did not install Datepicker in the vendor package. Thanks.

Rabib
  • 430
  • 7
  • 24
  • One more thing: when using `composer`, make sure you are **inside basic directory** ( if you have any ), otherwise you will install it in the wrong palce. – Peon Jun 04 '15 at 12:02
0

Do you have use .....\DatePicker; ?

Also are you including the jui asset and everything, take a look at the source, do you have jui and all the JS included?

Edit: Have you done a "composer update" lately?

Mihai P.
  • 9,307
  • 3
  • 38
  • 49
  • I donwloaded the file here http://jqueryui.com/ ,and put the css and js,under web directory,also i add it to appasset.php,but I get this error Class 'yii\jui\DatePicker' not found – ashTon Dec 06 '14 at 12:21
  • you did not install yii2 properly I believe. – Mihai P. Dec 06 '14 at 21:28
0

Use this code if you are using kartik datetime picker

<?= $form->field($model, 'date')->widget(DatePicker::classname(),['options' => ['placeholder' => 'Enter event time ...'],'pluginOptions' => [....]]) ?>
S. Gandhi
  • 109
  • 1
  • 10