ezekel
            (Dixunei)
          
          
          
              
              
          1
          
         
        
          Hi, I want to use the datepicker in yii2 basic but I could not show the datepicker in my form,
<?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>
Thank you in advance
         
        
          
        
           
           
           
         
         
            
            
          
       
      
        
          
          
            flarpy
            (Peter)
          
          
          
              
              
          2
          
         
        
          First ensure you have the necessary "use" statement at the top of the file eg use yii\jui\DatePicker
You need something like:
$form->field($model, 'periodfrom')->widget(DatePicker::classname(), [
               'clientOptions' => [
               'language' => 'en',
               'dateFormat' => 'yyyy-MM-dd',
           ]
        ]
         
        
        
           
           
           
         
         
            
            
          
       
      
        
          
          
            ezekel
            (Dixunei)
          
          
          
              
              
          3
          
         
        
          
Thank you for the quick reply,I already declare yii\jui\DatePicker from the top of my script, but I’m getting error
Thank you in advance
         
        
        
           
           
           
         
         
            
            
          
       
      
        
          
          
            EspinoVic
            (Victor Espino)
          
          
            
          
              
              
          4
          
         
        
          Use it like this:
   ->widget(DatePicker::class, [
                'clientOptions' => [
                'language' => 'en',
                'dateFormat' => 'yyyy-MM-dd',
            ]
        ])
change the class reference to → ::class
And install the library, by following the steps in here:
if the command:
php composer.phar require --prefer-dist yiisoft/yii2-jui
doesnt work for you, just run
composer.phar require --prefer-dist yiisoft/yii2-jui
Then run
php composer.phar require --prefer-dist yiisoft/yii2-jui
This will update you composer.json, now you just need to install the dependency by using command:
php composer install 
or
composer intall