Browse Source

Fixing issue with filterInputValidation variable in DataColumn

close #12089
tags/3.0.0-alpha1
Bob van Leeuwen 8 years ago committed by Carsten Brandt
parent
commit
7c85258c36
No known key found for this signature in database
GPG Key ID: BE4F41DE1DEEEED0
  1. 2
      framework/CHANGELOG.md
  2. 12
      framework/grid/DataColumn.php
  3. 64
      tests/framework/grid/DataColumnTest.php

2
framework/CHANGELOG.md

@ -19,6 +19,8 @@ Yii Framework 2 Change Log
- Chg #13080: Rename `yii\base\InvalidParamException` to `yii\base\InvalidArgumentException` (arogachev)
- Enh #2990: `yii\widgets\ActiveField::hiddenInput()` no longer renders label by default (lennartvdd)
- Chg: Moved masked input field widget into separate extension https://github.com/yiisoft/yii2-maskedinput (samdark)
- Chg #12089: Behavior of `yii\grid\DataColumn::$filterInputOptions` changed when default value is overwritten (bvanleeuwen, cebe)
2.0.11 under development
2.0.12 under development

12
framework/grid/DataColumn.php

@ -106,9 +106,11 @@ class DataColumn extends Column
* @var array the HTML attributes for the filter input fields. This property is used in combination with
* the [[filter]] property. When [[filter]] is not set or is an array, this property will be used to
* render the HTML attributes for the generated filter input fields.
* By default a `'class' => 'form-control'` element will be added if no class has been specified.
* If you do not want to create a class attribute, you can specify `['class' => null]`.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $filterInputOptions = ['class' => 'form-control', 'id' => null];
public $filterInputOptions = [];
/**
@ -186,17 +188,19 @@ class DataColumn extends Column
} else {
$error = '';
}
$filterOptions = array_merge(['class' => 'form-control', 'id' => null], $this->filterInputOptions);
if (is_array($this->filter)) {
$options = array_merge(['prompt' => ''], $this->filterInputOptions);
$options = array_merge(['prompt' => ''], $filterOptions);
return Html::activeDropDownList($model, $this->attribute, $this->filter, $options) . $error;
} elseif ($this->format === 'boolean') {
$options = array_merge(['prompt' => ''], $this->filterInputOptions);
$options = array_merge(['prompt' => ''], $filterOptions);
return Html::activeDropDownList($model, $this->attribute, [
$this->grid->formatter->booleanFormat[0],
$this->grid->formatter->booleanFormat[1],
], $options) . $error;
} else {
return Html::activeTextInput($model, $this->attribute, $this->filterInputOptions) . $error;
return Html::activeTextInput($model, $this->attribute, $filterOptions) . $error;
}
} else {
return parent::renderFilterCellContent();

64
tests/framework/grid/DataColumnTest.php

@ -7,6 +7,7 @@ use Yii;
use yii\data\ArrayDataProvider;
use yii\grid\DataColumn;
use yii\grid\GridView;
use yii\i18n\Formatter;
use yiiunit\data\ar\ActiveRecord;
use yiiunit\data\ar\Order;
@ -193,4 +194,67 @@ HTML
HTML
, $result);
}
public function filterOptionsProvider()
{
return [
[
false,
'<td><input type="text" class="form-control" name="Order[customer_id]"></td>',
],
[
['class' => 'form-control'],
'<td><input type="text" class="form-control" name="Order[customer_id]"></td>'
],
[
['class' => 'form-control', 'data' => ['value' => "1"]],
'<td><input type="text" class="form-control" name="Order[customer_id]" data-value="1"></td>'
],
[
['class' => ''],
'<td><input type="text" class="" name="Order[customer_id]"></td>'
],
[
['class' => null],
'<td><input type="text" name="Order[customer_id]"></td>'
],
[
['class' => 'form-control', 'id' => 'customer_id'],
'<td><input type="text" id="customer_id" class="form-control" name="Order[customer_id]"></td>'
],
[
['class' => '', 'id' => 'customer_id'],
'<td><input type="text" id="customer_id" class="" name="Order[customer_id]"></td>'
],
[
['class' => null, 'id' => 'customer_id'],
'<td><input type="text" id="customer_id" name="Order[customer_id]"></td>'
],
];
}
/**
* @dataProvider filterOptionsProvider
*/
public function testFilterInput_Options($options, $expectedHtml)
{
$this->mockApplication();
$column = new DataColumn([
'attribute' => 'customer_id',
'grid' => new GridView([
'filterModel' => new Order,
'dataProvider' => new ArrayDataProvider([
'allModels' => [],
'totalCount' => 0,
]),
]),
]);
if ($options !== false) {
$column->filterInputOptions = $options;
}
$filterCell = $column->renderFilterCell();
$this->assertEqualsWithoutLE($expectedHtml, $filterCell);
}
}

Loading…
Cancel
Save