File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ Yii2 multiple input change log
4
4
1.2.17 in development
5
5
---------------------
6
6
7
- - Enh: increased default value for the property ` limit `
7
+ - Enh: increased default value for the property ` limit ` (ivansal)
8
+ - Enh: Added support of associative array in data (ivansal)
8
9
9
10
1.2.16
10
11
------
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ Contents:
21
21
- [ Guess column title] ( #guess-column-title )
22
22
- [ Ajax loading of a widget] ( #ajax-loading )
23
23
- [ Use of a widget's placeholder] ( #using-placeholder )
24
+ - [ Custom index of the row] ( #custom-index )
24
25
- [ Javascript Events] ( #javascript-events )
25
26
- [ Renderers] ( #renderers )
26
27
417
418
?>
418
419
```
419
420
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
+
420
449
421
450
## JavaScript events
422
451
This widget has following events:
Original file line number Diff line number Diff line change @@ -117,9 +117,13 @@ protected function renderBody()
117
117
if ($ this ->min === $ this ->limit && $ cnt < $ this ->limit ) {
118
118
$ cnt = $ this ->limit ;
119
119
}
120
+
121
+ $ indices = array_keys ($ this ->data );
122
+
120
123
for ($ i = 0 ; $ i < $ cnt ; $ i ++) {
121
- $ item = ArrayHelper::getValue ($ this ->data , $ i , null );
122
- $ rows [] = $ this ->renderRowContent ($ i , $ item );
124
+ $ index = ArrayHelper::getValue ($ indices , $ i , $ i );
125
+ $ item = ArrayHelper::getValue ($ this ->data , $ index , null );
126
+ $ rows [] = $ this ->renderRowContent ($ index , $ item );
123
127
}
124
128
} elseif ($ this ->min > 0 ) {
125
129
for ($ i = 0 ; $ i < $ this ->min ; $ i ++) {
You can’t perform that action at this time.
0 commit comments