Skip to content

Commit cde3e0e

Browse files
authored
Merge pull request #176 from execut/adding-before-row-position
Added before row position
2 parents dad7c6f + 9306701 commit cde3e0e

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

CHANGELOG.md

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

44
2.11.0
55
======
6+
- Added the possibility to substitute buttons before rows
67

78
2.10.0
89
======

src/MultipleInput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MultipleInput extends InputWidget
2929
{
3030
const POS_HEADER = RendererInterface::POS_HEADER;
3131
const POS_ROW = RendererInterface::POS_ROW;
32+
const POS_ROW_BEGIN = RendererInterface::POS_ROW_BEGIN;
3233
const POS_FOOTER = RendererInterface::POS_FOOTER;
3334

3435
/**

src/renderers/BaseRenderer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ protected function isAddButtonPositionRow()
375375
return in_array(self::POS_ROW, $this->addButtonPosition);
376376
}
377377

378+
/**
379+
* @return bool
380+
*/
381+
protected function isAddButtonPositionRowBegin()
382+
{
383+
return in_array(self::POS_ROW_BEGIN, $this->addButtonPosition);
384+
}
385+
378386
private function prepareIndexPlaceholder()
379387
{
380388
$this->indexPlaceholder = 'multiple_index_' . $this->id;

src/renderers/RendererInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface RendererInterface
1717
{
1818
const POS_HEADER = 'header';
1919
const POS_ROW = 'row';
20+
const POS_ROW_BEGIN = 'row_begin';
2021
const POS_FOOTER = 'footer';
2122

2223
/**

src/renderers/TableRenderer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ private function renderRowContent($index = null, $item = null)
172172
{
173173
$cells = [];
174174
$hiddenInputs = [];
175+
$isLastRow = $this->max === $this->min;
176+
if (!$isLastRow && $this->isAddButtonPositionRowBegin()) {
177+
$cells[] = $this->renderActionColumn($index);
178+
}
175179

176180
foreach ($this->columns as $column) {
177181
/* @var $column BaseColumn */
@@ -183,7 +187,7 @@ private function renderRowContent($index = null, $item = null)
183187
}
184188
}
185189

186-
if ($this->max !== $this->min) {
190+
if (!$isLastRow && $this->isAddButtonPositionRow()) {
187191
$cells[] = $this->renderActionColumn($index);
188192
}
189193

@@ -292,7 +296,7 @@ private function getActionButton($index)
292296
if ($index < $this->min) {
293297
return '';
294298
} elseif ($index === $this->min) {
295-
return $this->isAddButtonPositionRow() ? $this->renderAddButton() : '';
299+
return ($this->isAddButtonPositionRow() || $this->isAddButtonPositionRowBegin()) ? $this->renderAddButton() : '';
296300
} else {
297301
return $this->renderRemoveButton();
298302
}

0 commit comments

Comments
 (0)