Skip to content

Commit 080dcfa

Browse files
committed
Adjust the code and update README
1 parent 5473a1b commit 080dcfa

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Yii2 multiple input change log
44
1.2.17 in development
55
---------------------
66

7-
- Enh: increased default value for the property `limit`
8-
- Added support of associative array in data
7+
- Enh: increased default value for the property `limit` (ivansal)
8+
- Enh: Added support of associative array in data (ivansal)
99

1010
1.2.16
1111
------
@@ -143,4 +143,4 @@ Yii2 multiple input change log
143143
1.0.0
144144
-----
145145

146-
first stable release
146+
first stable release

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Contents:
2121
- [Guess column title](#guess-column-title)
2222
- [Ajax loading of a widget](#ajax-loading)
2323
- [Use of a widget's placeholder](#using-placeholder)
24+
- [Custom index of the row](#custom-index)
2425
- [Javascript Events](#javascript-events)
2526
- [Renderers](#renderers)
2627

@@ -417,6 +418,34 @@ JS
417418
?>
418419
```
419420

421+
### Custom index of the row <a id="custom-index"></a>
422+
423+
Assume that you want to set specific index for each row. In this case you can pass the `data` attribute as associative array
424+
as in the example below:
425+
426+
```php
427+
<?= $form->field($model, 'field')->widget(MultipleInput::className(), [
428+
'allowEmptyList' => false,
429+
'data' => [
430+
3 => [
431+
'day' => '27.02.2015',
432+
'user_id' => 31,
433+
'priority' => 1,
434+
'enable' => 1
435+
],
436+
437+
'some-key' => [
438+
'day' => '27.02.2015',
439+
'user_id' => 33,
440+
'priority' => 2,
441+
'enable' => 0
442+
],
443+
]
444+
445+
...
446+
447+
```
448+
420449

421450
## JavaScript events
422451
This widget has following events:

src/renderers/TableRenderer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ protected function renderBody()
117117
if ($this->min === $this->limit && $cnt < $this->limit) {
118118
$cnt = $this->limit;
119119
}
120-
$keys = array_keys($this->data);
120+
121+
$indices = array_keys($this->data);
122+
121123
for ($i = 0; $i < $cnt; $i++) {
122-
$key = ArrayHelper::getValue($keys, $i, $i);
123-
$item = ArrayHelper::getValue($this->data, $key, null);
124-
$rows[] = $this->renderRowContent($key, $item);
124+
$index = ArrayHelper::getValue($indices, $i, $i);
125+
$item = ArrayHelper::getValue($this->data, $index, null);
126+
$rows[] = $this->renderRowContent($index, $item);
125127
}
126128
} elseif ($this->min > 0) {
127129
for ($i = 0; $i < $this->min; $i++) {

0 commit comments

Comments
 (0)