December 02 2015

Yii2 cactiveform client validation not working with fancybox ajax

Tagged Under :

Yii
If using fancybox ajax display the Yii2 cactiveform you will found that the client validation are not working.

Its due to the form ID was invalid or duplicated in same page. what you need to do is assign a new form id inside cactiveform.

Example
$form = ActiveForm::begin([
  'enableClientValidation' => true,
  'id' => 'new_form_id'
]);

December 02 2015

Yii2 gridview column pass an array as param

Tagged Under :

Yii
In Yii2 now you are allow pass an array as param to gridview column for display the data. Below is the example how to pass array to gridview column.

Exmaple:
The $status is an array and $data is the model results.
'content' => function($data) use ($status) {
  return (isset($status[$data->status]) ? $status[$data->status] : $data->status);
},

Complete Example:
 $model->search(),
  'filterModel' => $model,
  'showOnEmpty'=>true,
  'columns' => [
    'id',
    'name',
    [
      'attribute' => 'status',
      'filter' => $status,
      'content' => function($data) use ($status) {
        return (isset($status[$data->status]) ? $status[$data->status] : $data->status);
      },
    ],
  ],
]); ?>