Skip to content

Commit

Permalink
allow to omit a name for static columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Tupikov committed Nov 25, 2018
1 parent 47d37ba commit 2cb9807
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,7 +4,8 @@ Yii2 multiple input change log
2.18.0 (in development)
=======================
- #246 accept `\Traversable` in model attribute for `yield` compatibility (bscheshirwork)
- #250 accept `\Traversable` in TableRenderer and ListRenderer for `yield` compatibility (bscheshirwork)
- #250 accept `\Traversable` in TableRenderer and ListRenderer for `yield` compatibility (bscheshirwork)
- #253 allow to omit a name for static column

2.17.0
======
Expand Down
4 changes: 2 additions & 2 deletions examples/views/multiple-input.php
Expand Up @@ -124,7 +124,7 @@
]
],
[
'name' => 'comment',
'name' => 'comment', // can be ommited in case of static column
'type' => MultipleInputColumn::TYPE_STATIC,
'value' => function($data) {
return Html::tag('span', 'static content', ['class' => 'label label-info']);
Expand Down Expand Up @@ -180,4 +180,4 @@
});
JS;

$this->registerJs($js);
$this->registerJs($js);
16 changes: 11 additions & 5 deletions src/components/BaseColumn.php
Expand Up @@ -38,6 +38,8 @@ abstract class BaseColumn extends BaseObject

const TABINDEX = 1;

const DEFAULT_STATIC_COLUMN_NAME = 'static-column';

/**
* @var string input name
*/
Expand Down Expand Up @@ -128,7 +130,7 @@ abstract class BaseColumn extends BaseObject
* @since 2.8
*/
public $nameSuffix;

/**
* @var Model|ActiveRecordInterface|array
*/
Expand Down Expand Up @@ -165,14 +167,18 @@ public function init()
{
parent::init();

if (empty($this->name)) {
throw new InvalidConfigException("The 'name' option is required.");
}

if ($this->type === null) {
$this->type = self::TYPE_TEXT_INPUT;
}

if ($this->type === self::TYPE_STATIC && empty($this->name)) {
$this->name = self::DEFAULT_STATIC_COLUMN_NAME;
}

if (empty($this->name)) {
throw new InvalidConfigException("The 'name' option is required.");
}

if (empty($this->options)) {
$this->options = [];
}
Expand Down

0 comments on commit 2cb9807

Please sign in to comment.