Skip to content

Commit 2cb9807

Browse files
author
Eugene Tupikov
committed
allow to omit a name for static columns
1 parent 47d37ba commit 2cb9807

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Yii2 multiple input change log
44
2.18.0 (in development)
55
=======================
66
- #246 accept `\Traversable` in model attribute for `yield` compatibility (bscheshirwork)
7-
- #250 accept `\Traversable` in TableRenderer and ListRenderer for `yield` compatibility (bscheshirwork)
7+
- #250 accept `\Traversable` in TableRenderer and ListRenderer for `yield` compatibility (bscheshirwork)
8+
- #253 allow to omit a name for static column
89

910
2.17.0
1011
======

examples/views/multiple-input.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
]
125125
],
126126
[
127-
'name' => 'comment',
127+
'name' => 'comment', // can be ommited in case of static column
128128
'type' => MultipleInputColumn::TYPE_STATIC,
129129
'value' => function($data) {
130130
return Html::tag('span', 'static content', ['class' => 'label label-info']);
@@ -180,4 +180,4 @@
180180
});
181181
JS;
182182

183-
$this->registerJs($js);
183+
$this->registerJs($js);

src/components/BaseColumn.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ abstract class BaseColumn extends BaseObject
3838

3939
const TABINDEX = 1;
4040

41+
const DEFAULT_STATIC_COLUMN_NAME = 'static-column';
42+
4143
/**
4244
* @var string input name
4345
*/
@@ -128,7 +130,7 @@ abstract class BaseColumn extends BaseObject
128130
* @since 2.8
129131
*/
130132
public $nameSuffix;
131-
133+
132134
/**
133135
* @var Model|ActiveRecordInterface|array
134136
*/
@@ -165,14 +167,18 @@ public function init()
165167
{
166168
parent::init();
167169

168-
if (empty($this->name)) {
169-
throw new InvalidConfigException("The 'name' option is required.");
170-
}
171-
172170
if ($this->type === null) {
173171
$this->type = self::TYPE_TEXT_INPUT;
174172
}
175173

174+
if ($this->type === self::TYPE_STATIC && empty($this->name)) {
175+
$this->name = self::DEFAULT_STATIC_COLUMN_NAME;
176+
}
177+
178+
if (empty($this->name)) {
179+
throw new InvalidConfigException("The 'name' option is required.");
180+
}
181+
176182
if (empty($this->options)) {
177183
$this->options = [];
178184
}

0 commit comments

Comments
 (0)