Setting unknown property: kartik\widgets\DatePicker::_container

Hi.

I’ve got an error

Setting unknown property: kartik\widgets\DatePicker::_container

rendering a DatePicker widget ("kartik-v/yii2-widgets": "3.4.0") on Yii 2 ("yiisoft/yii2": "2.0.10"). This is the stacktrace:

This is part of the template code:


(...)

use kartik\widgets\DatePicker;

use yii\helpers\Html;

use yii\helpers\HtmlPurifier;

use yii\widgets\ActiveForm;

(...)

$layout_multiple = '{picker}{input}{remove}';

echo DatePicker::widget([

'name' => 'multiple_date_selection',

'value' => $model->multiple_date_selection,

'type' => DatePicker::TYPE_COMPONENT_PREPEND,

'model' => $model,

'form' => $form,

'attribute' => 'multiple_date_selection',

'layout' => $layout_multiple,

'options' => ['placeholder' => Yii::t('app', '(Select Multiple Dates)')],

'pluginOptions' => [

'format' => 'yyyy-mm-dd',

'multidate' => true,

'multidateSeparator' => ' ; ',

'todayHighlight' => true,

],

]);

(...)

Problem arises only when $form value is not null. I cannot understand what kind of object is “_container” and why it’s raising exception. Could it be related to form validation?

Thanks.

Usually you have to specify either

[list=1]

[*]a pair of ‘name’ and ‘value’,

[*]or a pair of ‘model’ and ‘attribute’.

[/list]

They are mutually exclusive. You don’t have to (or, rather, should not) specify ‘name’ and ‘value’ when you are using ‘model’ and ‘attribute’.

[edit]

And you could write like the following when you wanted to use a widget in an ActiveForm:




echo $form->field($model, 'multiple_date_selection')->widget(DatePicker::classname(), [

    'options' => ['placeholder' => 'Select the dates ...'],

    'pluginOptions' => [

        'autoclose'=>true

    ]

]);