Skip to content

Commit b98aefd

Browse files
author
Eugene Tupikov
committed
fix input name in case of one coumn and enabled sorting
1 parent 627a99b commit b98aefd

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Yii2 multiple input change log
44
2.23.0 (in development)
55
=======================
66
- Ability to add custom tabindex via options array
7+
- #335 fix input name in case of one coumn and enabled sorting
78

89
2.22.0
910
=======================

src/MultipleInputColumn.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ public function getElementName($index, $withPrefix = true)
7070
*/
7171
private function isRendererHasOneColumn()
7272
{
73-
return count($this->renderer->columns) === 1;
73+
$columns = \array_filter($this->renderer->columns, function(self $column) {
74+
return $column->type !== self::TYPE_DRAGCOLUMN;
75+
});
76+
77+
return count($columns) === 1;
7478
}
7579

7680
/**
@@ -85,10 +89,10 @@ protected function getInputNamePrefix()
8589
if (empty($this->renderer->columns) || ($this->isRendererHasOneColumn() && $this->hasModelAttribute($this->name))) {
8690
return $model->formName();
8791
}
88-
92+
8993
return Html::getInputName($this->context->model, $this->context->attribute);
9094
}
91-
95+
9296
return $this->context->name;
9397
}
9498

@@ -120,7 +124,7 @@ public function getFirstError($index)
120124
if ($index === null) {
121125
return null;
122126
}
123-
127+
124128
if ($this->isRendererHasOneColumn()) {
125129
$attribute = $this->name . '[' . $index . ']';
126130
} else {
@@ -161,12 +165,12 @@ protected function renderWidget($type, $name, $value, $options)
161165
$options['attribute'] = $attribute;
162166

163167
// Remember current name and mark the widget as embedded to prevent
164-
// generation of wrong prefix in case when column is associated with AR relation
168+
// generation of wrong prefix in case the column is associated with AR relation
165169
// @see https://github.com/unclead/yii2-multiple-input/issues/92
166170
$options['name'] = $name;
167171
$options['isEmbedded'] = true;
168172
}
169173

170174
return parent::renderWidget($type, $name, $value, $options);
171175
}
172-
}
176+
}

src/renderers/DivRenderer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use yii\helpers\UnsetArrayValue;
1717

1818
/**
19-
* Class DivRenderer is a list renderer who use divs
19+
* Class DivRenderer is a list renderer which uses divs
20+
*
2021
* @package unclead\multipleinput\renderers
2122
*/
2223
class DivRenderer extends BaseRenderer
@@ -185,9 +186,10 @@ public function renderCellContent($column, $index, $columnIndex = null)
185186
* via the $options array
186187
*/
187188
$options = ['id' => $id];
188-
if (substr($id, -4) === 'drag') {
189+
if ($column->type === BaseColumn::TYPE_DRAGCOLUMN) {
189190
$options = ArrayHelper::merge($options, ['class' => $this->iconMap['drag-handle']]);
190191
}
192+
191193
$input = $column->renderInput($name, $options, [
192194
'id' => $id,
193195
'name' => $name,

src/renderers/ListRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function renderCellContent($column, $index, $columnIndex = null)
201201
* via the $options array
202202
*/
203203
$options = ['id' => $id];
204-
if (substr($id, -4) === 'drag') {
204+
if ($column->type === BaseColumn::TYPE_DRAGCOLUMN) {
205205
$options = ArrayHelper::merge($options, ['class' => $this->iconMap['drag-handle']]);
206206
}
207207

src/renderers/TableRenderer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,11 @@ public function renderCellContent($column, $index, $columnIndex = null)
278278
* via the $options array
279279
*/
280280
$options = ['id' => $id];
281-
if (substr($id, -4) === 'drag') {
281+
if ($column->type === BaseColumn::TYPE_DRAGCOLUMN) {
282282
$options = ArrayHelper::merge($options, ['class' => $this->iconMap['drag-handle']]);
283283
}
284284

285+
285286
$input = $column->renderInput($name, $options, [
286287
'id' => $id,
287288
'name' => $name,

0 commit comments

Comments
 (0)