Skip to content

Commit 08e495d

Browse files
committed
global option enableError
1 parent ad43b3d commit 08e495d

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Yii2 multiple input change log
33

44
2.10.0
55
======
6-
6+
- #170: Added global options `enableError`
77
- #154: Added missing js event: beforeAddRow
88

99
2.9.0

src/MultipleInput.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ class MultipleInput extends InputWidget
129129
*/
130130
public $sortable = false;
131131

132+
/**
133+
* @var bool whether to render inline error for all input. Default to `false`. Can be override in `columns`
134+
* @since 2.10
135+
*/
136+
public $enableError = false;
137+
132138
/**
133139
* Initialization.
134140
*
@@ -238,7 +244,8 @@ private function createRenderer()
238244
'rowOptions' => $this->rowOptions,
239245
'context' => $this,
240246
'form' => $this->form,
241-
'sortable' => $this->sortable
247+
'sortable' => $this->sortable,
248+
'enableError' => $this->enableError,
242249
];
243250

244251
if ($this->removeButtonOptions !== null) {

src/TabularInput.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ class TabularInput extends Widget
115115
*/
116116
public $sortable = false;
117117

118+
/**
119+
* @var bool whether to render inline error for all input. Default to `false`. Can be override in `columns`
120+
* @since 2.10
121+
*/
122+
public $enableError = false;
123+
118124
/**
119125
* Initialization.
120126
*
@@ -165,7 +171,8 @@ private function createRenderer()
165171
'addButtonPosition' => $this->addButtonPosition,
166172
'context' => $this,
167173
'form' => $this->form,
168-
'sortable' => $this->sortable
174+
'sortable' => $this->sortable,
175+
'enableError' => $this->enableError,
169176
];
170177

171178
if ($this->removeButtonOptions !== null) {

src/renderers/BaseRenderer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ abstract class BaseRenderer extends Object implements RendererInterface
126126
*/
127127
public $sortable = false;
128128

129+
/**
130+
* @var bool whether to render inline error for all input. Default to `false`. Can be override in `columns`
131+
* @since 2.10
132+
*/
133+
public $enableError = false;
134+
129135
/**
130136
* @inheritdoc
131137
*/
@@ -243,6 +249,10 @@ protected function initColumns()
243249
$definition['attributeOptions'] = $this->attributeOptions;
244250
}
245251

252+
if (!array_key_exists('enableError', $definition)) {
253+
$definition['enableError'] = $this->enableError;
254+
}
255+
246256
$this->columns[$i] = Yii::createObject($definition);
247257
}
248258
}

tests/unit/MultipleInputTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ public function testGuessColumn()
2828
$this->assertEquals($expected, $widget->columns);
2929
}
3030

31+
public function testGlobalErrorGuessColumn()
32+
{
33+
$model = new TestModel();
34+
35+
$widget = new MultipleInput([
36+
'model' => $model,
37+
'attribute' => 'email',
38+
'enableError' => true,
39+
]);
40+
41+
$expected = [
42+
['name' => 'email', 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, 'enableError' => true]
43+
];
44+
45+
$this->assertEquals($expected, $widget->columns);
46+
}
47+
3148
public function testInitData()
3249
{
3350
$model = new TestModel();

0 commit comments

Comments
 (0)