Commit 61841345 by Carsten Brandt

Merge pull request #3164 from ivan-kolmychek/3154-gridview-filter-error-indication

GridView filter error indication added (#3154)
parents f1ff318a bb4e8eb7
......@@ -143,6 +143,9 @@ class DataColumn extends Column
return $this->filter;
} elseif ($this->filter !== false && $this->grid->filterModel instanceof Model &&
$this->attribute !== null && $this->grid->filterModel->isAttributeActive($this->attribute)) {
if ($this->grid->filterModel->hasErrors($this->attribute)) {
Html::addCssClass($this->filterOptions, 'has-error');
}
if (is_array($this->filter)) {
$options = array_merge(['prompt' => ''], $this->filterInputOptions);
return Html::activeDropDownList($this->grid->filterModel, $this->attribute, $this->filter, $options);
......
......@@ -15,6 +15,8 @@ use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\BaseListView;
use yii\helpers\ArrayHelper;
use yii\base\Model;
/**
* The GridView widget is used to display data in a grid.
......@@ -174,6 +176,17 @@ class GridView extends BaseListView
*/
public $filterRowOptions = ['class' => 'filters'];
/**
* @var string the layout that determines how different sections of the list view should be organized.
* The following tokens will be replaced with the corresponding section contents:
*
* - `{summary}`: the summary section. See [[renderSummary()]].
* - `{error}`: the filter model errors. See [[renderErrors()]].
* - `{items}`: the list items. See [[renderItems()]].
* - `{sorter}`: the sorter. See [[renderSorter()]].
* - `{pager}`: the pager. See [[renderPager()]].
*/
public $layout = "{summary}\n{errors}\n{items}\n{pager}";
/**
* Initializes the grid view.
......@@ -212,7 +225,35 @@ class GridView extends BaseListView
$view->registerJs("jQuery('#$id').yiiGridView($options);");
parent::run();
}
/**
* @inheritdoc
*/
public function renderErrors()
{
if ($this->filterModel instanceof Model && $this->filterModel->hasErrors())
{
$errorsList = [];
foreach($this->filterModel->errors as $attribute => $errors)
{
$errorsList = ArrayHelper::merge($errorsList, $errors);
}
return Html::tag('div', Html::ul($errorsList, ['class' => 'help-block']), ['class' => 'has-error']);
}
return '';
}
public function renderSection($name)
{
switch ($name) {
case "{errors}":
return $this->renderErrors();
default:
return parent::renderSection($name);
}
}
/**
* Returns the options for the grid view JS widget.
* @return array the options
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment