File tree Expand file tree Collapse file tree 4 files changed +33
-7
lines changed Expand file tree Collapse file tree 4 files changed +33
-7
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.3 in development
5
5
--------------------
6
6
7
- - Enh #34 : Added options ` allowEmptyList ` (unclead)
7
+ - Enh #34 : Added option ` allowEmptyList ` (unclead)
8
+ - Enh #35 : Added option ` enableGuessTitle ` for MultipleInput (unclead)
8
9
9
10
1.2.2
10
11
-----
Original file line number Diff line number Diff line change @@ -280,6 +280,22 @@ In some cases you need to have the ability to delete all rows in the list. For t
280
280
281
281
```
282
282
283
+ ### Guess column title
284
+
285
+ Sometimes you can use the widget without defining columns but you want to have the column header of the table.
286
+ In this case you can use ` enableGuessColumn ` option like in the example below:
287
+
288
+ ``` php
289
+
290
+ echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
291
+ 'limit' => 5,
292
+ 'allowEmptyList' => true,
293
+ 'enableGuessTitle' => true
294
+ ])
295
+ ->label(false);
296
+
297
+ ```
298
+
283
299
## JavaScript events
284
300
This widget has following events:
285
301
- ` afterInit ` : triggered after initialization
Original file line number Diff line number Diff line change 25
25
<?php
26
26
echo $ form ->field ($ model , 'emails ' )->widget (MultipleInput::className (), [
27
27
'limit ' => 5 ,
28
- 'allowEmptyList ' => true
28
+ 'allowEmptyList ' => true ,
29
+ 'enableGuessTitle ' => true
29
30
])
30
31
->label (false );
31
32
?>
Original file line number Diff line number Diff line change @@ -59,6 +59,11 @@ class MultipleInput extends InputWidget
59
59
*/
60
60
public $ allowEmptyList = false ;
61
61
62
+ /**
63
+ * @var bool whether to guess column title in case if there is no definition of columns
64
+ */
65
+ public $ enableGuessTitle = false ;
66
+
62
67
63
68
/**
64
69
* Initialization.
@@ -91,12 +96,15 @@ protected function initData()
91
96
protected function guessColumns ()
92
97
{
93
98
if (empty ($ this ->columns ) && $ this ->hasModel ()) {
94
- $ this ->columns = [
95
- [
96
- 'name ' => $ this ->attribute ,
97
- 'type ' => MultipleInputColumn::TYPE_TEXT_INPUT
98
- ]
99
+ $ column = [
100
+ 'name ' => $ this ->attribute ,
101
+ 'type ' => MultipleInputColumn::TYPE_TEXT_INPUT
99
102
];
103
+
104
+ if ($ this ->enableGuessTitle && $ this ->hasModel ()) {
105
+ $ column ['title ' ] = $ this ->model ->getAttributeLabel ($ this ->attribute );
106
+ }
107
+ $ this ->columns [] = $ column ;
100
108
}
101
109
}
102
110
You can’t perform that action at this time.
0 commit comments