Skip to content

Commit 06bc83b

Browse files
committed
fixed rendering of an action column
1 parent 05ab8ba commit 06bc83b

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Yii2 widget for handle multiple inputs for an attribute of model and tabular inp
88
[![License](https://poser.pugx.org/unclead/yii2-multiple-input/license)](https://packagist.org/packages/unclead/yii2-multiple-input)
99

1010
## Latest release
11-
The latest stable version of the extension is v2.11.2 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
11+
The latest stable version of the extension is v2.11.3 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
1212

1313
## Installation
1414
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"yii2 tabular input"
1010
],
1111
"type": "yii2-extension",
12-
"version": "2.11.2",
12+
"version": "2.11.3",
1313
"license": "BSD-3-Clause",
1414
"support": {
1515
"issues": "https://github.com/unclead/yii2-multiple-input/issues?state=open",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery.multipleInput",
3-
"version": "2.11.2",
3+
"version": "2.11.3",
44
"description": "jQuery multipleInput",
55
"scripts": {
66
"build": "npm install && (gulp || node node_modules/gulp/bin/gulp.js)"

src/renderers/TableRenderer.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private function renderRowContent($index = null, $item = null)
174174
$hiddenInputs = [];
175175
$isLastRow = $this->max === $this->min;
176176
if (!$isLastRow && $this->isAddButtonPositionRowBegin()) {
177-
$cells[] = $this->renderActionColumn($index);
177+
$cells[] = $this->renderActionColumn($index, true);
178178
}
179179

180180
foreach ($this->columns as $column) {
@@ -187,8 +187,8 @@ private function renderRowContent($index = null, $item = null)
187187
}
188188
}
189189

190-
if (!$isLastRow && !$this->isAddButtonPositionRow()) {
191-
$cells[] = $this->renderActionColumn($index);
190+
if (!$isLastRow) {
191+
$cells[] = $this->renderActionColumn($index, false);
192192
}
193193

194194
if ($hiddenInputs) {
@@ -276,30 +276,44 @@ public function renderCellContent($column, $index)
276276
* Renders the action column.
277277
*
278278
* @param null|int $index
279+
* @param bool $isFirstColumn
279280
* @return string
280-
* @throws \Exception
281281
*/
282-
private function renderActionColumn($index = null)
282+
private function renderActionColumn($index = null, $isFirstColumn = false)
283283
{
284-
return Html::tag('td', $this->getActionButton($index), [
284+
return Html::tag('td', $this->getActionButton($index, $isFirstColumn), [
285285
'class' => 'list-cell__button',
286286
]);
287287
}
288288

289-
private function getActionButton($index)
289+
private function getActionButton($index, $isFirstColumn)
290290
{
291291
if ($index === null || $this->min === 0) {
292-
return $this->renderRemoveButton();
292+
if ($isFirstColumn) {
293+
return $this->isAddButtonPositionRowBegin() ? $this->renderRemoveButton() : '';
294+
}
295+
296+
return $this->isAddButtonPositionRowBegin() ? '' : $this->renderRemoveButton();
293297
}
294298

295299
$index++;
296300
if ($index < $this->min) {
297301
return '';
298-
} elseif ($index === $this->min) {
299-
return ($this->isAddButtonPositionRow() || $this->isAddButtonPositionRowBegin()) ? $this->renderAddButton() : '';
300-
} else {
301-
return $this->renderRemoveButton();
302302
}
303+
304+
if ($index === $this->min) {
305+
if ($isFirstColumn) {
306+
return $this->isAddButtonPositionRowBegin() ? $this->renderAddButton() : '';
307+
}
308+
309+
return $this->isAddButtonPositionRow() ? $this->renderAddButton() : '';
310+
}
311+
312+
if ($isFirstColumn) {
313+
return $this->isAddButtonPositionRowBegin() ? $this->renderRemoveButton() : '';
314+
}
315+
316+
return $this->isAddButtonPositionRowBegin() ? '' : $this->renderRemoveButton();
303317
}
304318

305319
private function renderAddButton()

0 commit comments

Comments
 (0)