File tree Expand file tree Collapse file tree 7 files changed +26
-3
lines changed Expand file tree Collapse file tree 7 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ Widget support the following options that are additionally recognized over and a
47
47
- ` removeButtonOptions ` * array* : the HTML options for ` add ` button. Can contains ` class ` and ` label ` keys
48
48
- ` data ` * array* : array of values in case you use widget without model
49
49
- ` models ` * array* : the list of models. Required in case you use ` TabularInput ` widget
50
+ - ` allowEmptyList ` * boolean* : whether to allow the empty list
50
51
- ` columns ` * array* : the row columns configuration where you can set the following properties:
51
52
- ` name ` * string* : input name. * Required options*
52
53
- ` type ` * string* : type of the input. If not set will default to ` textInput ` . Read more about the types described below
Original file line number Diff line number Diff line change 33
33
<?= $ form ->field ($ model , 'schedule ' )->widget (MultipleInput::className (), [
34
34
'id ' => 'schedule-wrapper ' ,
35
35
'limit ' => 4 ,
36
+ 'allowEmptyList ' => true ,
36
37
'columns ' => [
37
38
[
38
39
'name ' => 'user_id ' ,
Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ class MultipleInput extends InputWidget
54
54
*/
55
55
public $ addButtonOptions ;
56
56
57
+ /**
58
+ * @var bool whether to allow the empty list
59
+ */
60
+ public $ allowEmptyList = false ;
61
+
57
62
58
63
/**
59
64
* Initialization.
@@ -115,6 +120,7 @@ private function createRenderer()
115
120
'attributeOptions ' => $ this ->attributeOptions ,
116
121
'data ' => $ this ->data ,
117
122
'columnClass ' => MultipleInputColumn::className (),
123
+ 'allowEmptyList ' => $ this ->allowEmptyList ,
118
124
'context ' => $ this
119
125
];
120
126
Original file line number Diff line number Diff line change @@ -48,6 +48,11 @@ class TabularInput extends Widget
48
48
*/
49
49
public $ addButtonOptions ;
50
50
51
+ /**
52
+ * @var bool whether to allow the empty list
53
+ */
54
+ public $ allowEmptyList = false ;
55
+
51
56
/**
52
57
* @var Model[]|ActiveRecord[]
53
58
*/
@@ -94,6 +99,7 @@ private function createRenderer()
94
99
'attributeOptions ' => $ this ->attributeOptions ,
95
100
'data ' => $ this ->models ,
96
101
'columnClass ' => TabularColumn::className (),
102
+ 'allowEmptyList ' => $ this ->allowEmptyList ,
97
103
'context ' => $ this
98
104
];
99
105
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ table.multiple-input-list tr > th {
34
34
display : block;
35
35
font-size : 13px ;
36
36
}
37
- .multiple-input-list__item .list-cell__button {
37
+ .multiple-input-list .list-cell__button {
38
38
width : 40px ;
39
39
}
40
40
.multiple-input-list__item .radio ,
Original file line number Diff line number Diff line change @@ -64,11 +64,17 @@ abstract class BaseRenderer extends Object
64
64
*/
65
65
public $ addButtonOptions ;
66
66
67
+ /**
68
+ * @var bool whether to allow the empty list
69
+ */
70
+ public $ allowEmptyList = false ;
71
+
67
72
/**
68
73
* @var string
69
74
*/
70
75
public $ columnClass ;
71
76
77
+
72
78
/**
73
79
* @var TabularInput|MultipleInput
74
80
*/
Original file line number Diff line number Diff line change @@ -56,7 +56,8 @@ public function renderHeader()
56
56
$ cells [] = $ this ->renderHeaderCell ($ column );
57
57
}
58
58
if (is_null ($ this ->limit ) || $ this ->limit > 1 ) {
59
- $ cells [] = Html::tag ('th ' , '' , [
59
+ $ button = $ this ->allowEmptyList ? $ this ->renderAddButton () : '' ;
60
+ $ cells [] = Html::tag ('th ' , $ button , [
60
61
'class ' => 'list-cell__button '
61
62
]);
62
63
}
@@ -204,8 +205,10 @@ private function renderActionColumn($index = null)
204
205
{
205
206
if (is_null ($ index )) {
206
207
$ button = $ this ->renderRemoveButton ();
208
+ } elseif ($ index == 0 ) {
209
+ $ button = $ this ->allowEmptyList ? $ this ->renderRemoveButton () : $ this ->renderAddButton ();
207
210
} else {
208
- $ button = $ index == 0 ? $ this -> renderAddButton () : $ this ->renderRemoveButton ();
211
+ $ button = $ this ->renderRemoveButton ();
209
212
}
210
213
211
214
return Html::tag ('td ' , $ button , [
You can’t perform that action at this time.
0 commit comments