Skip to content

Commit e7e966a

Browse files
author
Eugene Tupikov
committed
sync options + fixed markup
1 parent 5db3e19 commit e7e966a

File tree

5 files changed

+99
-19
lines changed

5 files changed

+99
-19
lines changed

examples/views/tabular-input.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,25 @@
2323
'models' => $models,
2424
'modelClass' => Item::class,
2525
'rendererClass' => ListRenderer::class,
26+
'cloneButton' => true,
2627
'min' => 0,
28+
'addButtonPosition' => [
29+
TabularInput::POS_HEADER,
30+
TabularInput::POS_FOOTER,
31+
TabularInput::POS_ROW
32+
],
2733
'layoutConfig' => [
28-
'offsetClass' => 'col-sm-offset-4',
29-
'labelClass' => 'col-sm-4',
30-
'wrapperClass' => 'col-sm-4',
31-
'errorClass' => 'col-sm-4'
34+
'offsetClass' => 'col-sm-offset-4',
35+
'labelClass' => 'col-sm-2',
36+
'wrapperClass' => 'col-sm-10',
37+
'errorClass' => 'col-sm-4'
3238
],
3339
'attributeOptions' => [
34-
'enableAjaxValidation' => true,
40+
'enableAjaxValidation' => true,
3541
'enableClientValidation' => false,
36-
'validateOnChange' => false,
37-
'validateOnSubmit' => true,
38-
'validateOnBlur' => false,
42+
'validateOnChange' => false,
43+
'validateOnSubmit' => true,
44+
'validateOnBlur' => false,
3945
],
4046
'form' => $form,
4147
'columns' => [

src/MultipleInput.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ class MultipleInput extends InputWidget
160160
*/
161161
public $extraButtons;
162162

163+
/**
164+
* @var array CSS grid classes for horizontal layout. This must be an array with these keys:
165+
* - 'offsetClass' the offset grid class to append to the wrapper if no label is rendered
166+
* - 'labelClass' the label grid class
167+
* - 'wrapperClass' the wrapper grid class
168+
* - 'errorClass' the error grid class
169+
*/
170+
public $layoutConfig = [];
171+
163172
/**
164173
* @var array
165174
* --icon library classes mapped for various controls
@@ -283,7 +292,10 @@ private function createRenderer()
283292
/**
284293
* set default icon map
285294
*/
286-
$iconmap = array_key_exists($this->iconSource, $this->iconMap) ? $this->iconMap[$this->iconSource] : $this->iconMap['glyphicons'];
295+
$iconMap = array_key_exists($this->iconSource, $this->iconMap)
296+
? $this->iconMap[$this->iconSource]
297+
: $this->iconMap['glyphicons'];
298+
287299
$config = [
288300
'id' => $this->getId(),
289301
'columns' => $this->columns,
@@ -301,7 +313,8 @@ private function createRenderer()
301313
'enableError' => $this->enableError,
302314
'cloneButton' => $this->cloneButton,
303315
'extraButtons' => $this->extraButtons,
304-
'iconMap' => $iconmap,
316+
'layoutConfig' => $this->layoutConfig,
317+
'iconMap' => $iconMap,
305318
];
306319

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

src/TabularInput.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ class TabularInput extends Widget
132132
*/
133133
public $cloneButton = false;
134134

135+
/**
136+
* @var string|\Closure the HTML content that will be rendered after the buttons.
137+
*
138+
* ```php
139+
* function ($model, $index, $context)
140+
* ```
141+
*
142+
* - `$model`: the current data model being rendered
143+
* - `$index`: the zero-based index of the data model in the model array
144+
* - `$context`: the MultipleInput widget object
145+
*
146+
*/
147+
public $extraButtons;
148+
135149
/**
136150
* @var string a class of model which is used to render the widget.
137151
* You have to specify this property in case you set `min` property to 0 (when you want to allow an empty list)
@@ -227,7 +241,10 @@ private function createRenderer()
227241
/**
228242
* set default icon map
229243
*/
230-
$iconmap = array_key_exists($this->iconSource, $this->iconMap) ? $this->iconMap[$this->iconSource] : $this->iconMap['glyphicons'];
244+
$iconMap = array_key_exists($this->iconSource, $this->iconMap)
245+
? $this->iconMap[$this->iconSource]
246+
: $this->iconMap['glyphicons'];
247+
231248
$config = [
232249
'id' => $this->getId(),
233250
'columns' => $this->columns,
@@ -243,8 +260,10 @@ private function createRenderer()
243260
'form' => $this->form,
244261
'sortable' => $this->sortable,
245262
'enableError' => $this->enableError,
263+
'cloneButton' => $this->cloneButton,
264+
'extraButtons' => $this->extraButtons,
246265
'layoutConfig' => $this->layoutConfig,
247-
'iconMap' => $iconmap,
266+
'iconMap' => $iconMap,
248267
];
249268

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

src/assets/src/css/multiple-input.css

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,85 @@
1-
.multiple-input-list {}
1+
.multiple-input-list {
2+
}
3+
24
.multiple-input-list__item {
35
margin-bottom: 5px;
46
}
7+
58
.multiple-input-list__input {
69
display: inline-block;
710
width: 80%;
811
}
12+
913
.multiple-input-list.no-buttons .multiple-input-list__input {
1014
display: block;
1115
width: 100%;
1216
}
17+
1318
table.multiple-input-list {
1419
margin: 0;
1520
}
21+
1622
table.multiple-input-list.table-renderer tbody tr > td {
1723
border: 0 !important;
1824
}
25+
1926
table.multiple-input-list.table-renderer tr > td:first-child {
2027
padding-left: 0;
2128
}
29+
2230
table.multiple-input-list.table-renderer tr > td:last-child {
2331
padding-right: 0;
2432
}
33+
2534
table.multiple-input-list tr > th {
2635
border-bottom: 1px solid #dddddd;
2736
}
37+
2838
.multiple-input-list.table-renderer .form-group {
2939
margin: 0 !important;
3040
}
41+
3142
.multiple-input-list.list-renderer .form-group {
3243
margin-bottom: 10px !important;
3344
}
45+
3446
.multiple-input-list.table-renderer .multiple-input-list__item .label {
3547
display: block;
3648
font-size: 13px;
3749
}
50+
3851
.multiple-input-list.table-renderer .list-cell__button {
3952
width: 40px;
4053
}
54+
4155
.multiple-input-list.list-renderer .list-cell__button {
42-
width: 70px;
56+
width: 40px;
4357
text-align: right;
44-
padding-right: 15px;
58+
padding-right: 0;
59+
padding-left: 5px;
4560
}
61+
62+
.multiple-input-list.list-renderer tbody .list-cell__button .btn{
63+
margin-top: 25px;
64+
}
65+
4666
.multiple-input-list__item .radio,
4767
.multiple-input-list__item .checkbox {
4868
margin: 7px 0 7px 0;
4969
}
70+
5071
.multiple-input-list__item .radio-list .radio,
5172
.multiple-input-list__item .checkbox-list .checkbox {
5273
margin: 0;
5374
}
75+
5476
.multiple-input-list .multiple-input-list {
5577
margin-top: -5px;
78+
}
79+
80+
@media (min-width: 768px) {
81+
.multiple-input-list.list-renderer tbody .list-cell__button .btn {
82+
margin-top: 0;
83+
}
84+
5685
}

src/renderers/TableRenderer.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ public function renderHeader()
5858
$cells[] = $this->renderHeaderCell($column);
5959
}
6060

61+
62+
6163
if ($this->max === null || ($this->max >= 1 && $this->max !== $this->min)) {
6264
$button = $this->isAddButtonPositionHeader() ? $this->renderAddButton() : '';
6365

64-
$cells[] = $this->renderButtonHeaderCell($button);
65-
6666
if ($this->cloneButton) {
6767
$cells[] = $this->renderButtonHeaderCell();
6868
}
69+
70+
$cells[] = $this->renderButtonHeaderCell($button);
6971
}
7072

7173
return Html::tag('thead', Html::tag('tr', implode("\n", $cells)));
@@ -82,8 +84,19 @@ public function renderFooter()
8284
return '';
8385
}
8486

87+
$columnsCount = 0;
88+
foreach ($this->columns as $column) {
89+
if (!$column->isHiddenInput()) {
90+
$columnsCount++;
91+
}
92+
}
93+
94+
if ($this->cloneButton) {
95+
$columnsCount++;
96+
}
97+
8598
$cells = [];
86-
$cells[] = Html::tag('td', ' ', ['colspan' => count($this->columns)]);
99+
$cells[] = Html::tag('td', ' ', ['colspan' => $columnsCount]);
87100
$cells[] = Html::tag('td', $this->renderAddButton(), [
88101
'class' => 'list-cell__button'
89102
]);
@@ -203,7 +216,7 @@ private function renderRowContent($index = null, $item = null)
203216
if ($this->cloneButton) {
204217
$cells[] = $this->renderCloneColumn();
205218
}
206-
219+
207220
if (!$isLastRow) {
208221
$cells[] = $this->renderActionColumn($index, $item);
209222
}

0 commit comments

Comments
 (0)