Closed o-shabashov closed 9 years ago
You need to use a tabular rendering (it can be solved if the attribute is an array)
How did you solved the issue?? Pls explain with the above example
@yuvraj7737 The problem it has its due that the same ID is given for any DateRangePicker element in the page. The only way to solve it if you do have an array property and collect them independently. Here is a good example on how to work with Tabular Inputs: http://www.yiiframework.com/doc/guide/1.1/en/form.table
Hi, Thanks for your response. Let me explain you my use case.
The problem:
How do I instantiate the model for every row in the gridview.
I have the same problem, any solution?
I got a result. On my index.php I have the GridView and its expand row, which renders partial another view as seen below:
<?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'export' => false, 'columns' => [ [ 'class' => 'kartik\grid\ExpandRowColumn', 'value' => function ($model, $key, $index, $column) { return GridView::ROW_COLLAPSED; }, 'detail' => function ($model, $key, $index, $column) { $myModel= Model::findOne(['AField' => $model->MyField]); return Yii::$app->controller->renderPartial('_my_view', [ 'model' => $myModel, 'contador' => GridView::$counter, //HERE IS THE MAGIC ]); }, ], ], ]); ?>
On _my_view I have the widget like that:
echo DateTimePicker::widget([ 'model' => $model, 'attribute' => 'Date', 'type' => DateTimePicker::TYPE_COMPONENT_APPEND, 'readonly' => true, 'options' => ['id' => 'calendar'.$contador], //HERE IS THE MAGIC ONE MORE TIME 'pluginOptions' => [ 'autoclose' => true, 'format' => 'dd/mm/yyyy HH:ii', 'hoursDisabled' => '0,1,2,3,4,5,6,7,22,23,24', ] ]); ?>
This is my way to solve the issue. The GridView::$counter has the index of each row, so the 'Id' of the DateTimePicker also changes in each row. Hope it's helpful ;)
Hello.
If i display same form multiple times at one page, DatePickerRange dosn`t appear more than 1 time (at first element).
Sample: $form = ActiveForm::begin(); echo $form->field($model, 'date_attended_from')->widget(DateRangePicker::className(), [ 'attributeTo' => 'date_attended_to', 'form' => $form, 'clientOptions' => [ 'autoclose' => true, 'format' => 'yyyy-mm-dd' ] ]); ActiveForm::end();
$form = ActiveForm::begin(); echo $form->field($model, 'date_attended_from')->widget(DateRangePicker::className(), [ 'attributeTo' => 'date_attended_to', 'form' => $form, 'clientOptions' => [ 'autoclose' => true, 'format' => 'yyyy-mm-dd' ] ]); ActiveForm::end();
I think problem in duplicate id attribute. What can i do to fix that?