@@ -8,7 +8,7 @@ Yii2 widget for handle multiple inputs for an attribute of model
8
8
[ ![ License] ( https://poser.pugx.org/unclead/yii2-multiple-input/license )] ( https://packagist.org/packages/unclead/yii2-multiple-input )
9
9
10
10
##Latest release
11
- The latest version of the extension is v1.2.5 . Follow the [ instruction] ( ./UPGRADE.md ) for upgrading from previous versions
11
+ The latest version of the extension is v1.2.6 . Follow the [ instruction] ( ./UPGRADE.md ) for upgrading from previous versions
12
12
13
13
Contents:
14
14
@@ -38,28 +38,61 @@ to the require section of your `composer.json` file.
38
38
39
39
## Configuration
40
40
41
- Widget support the following options that are additionally recognized over and above the configuration options in the InputWidget:
41
+ Widget support the following options that are additionally recognized over and above the configuration options in the InputWidget.
42
42
43
- - ` limit ` * integer* : rows limit. If not set will defaul to unlimited
44
- - ` attributeOptions ` * array* : client-side attribute options, e.g. enableAjaxValidation. You may use this property in case when
43
+ ### Base options
44
+
45
+ ** limit** * integer* : rows limit. If not set will defaul to unlimited
46
+
47
+ ** min** * integer* : minimum number of rows. Set to ` 0 ` if you need the empty list in case you don't have any data
48
+
49
+ ** attributeOptions** * array* : client-side attribute options, e.g. enableAjaxValidation. You may use this property in case when
45
50
you use widget without a model, since in this case widget is not able to detect client-side options automatically
46
- - ` addButtonOptions ` * array* : the HTML options for ` add ` button. Can contains ` class ` and ` label ` keys
47
- - ` removeButtonOptions ` * array* : the HTML options for ` add ` button. Can contains ` class ` and ` label ` keys
48
- - ` data ` * array* : array of values in case you use widget without model
49
- - ` models ` * array* : the list of models. Required in case you use ` TabularInput ` widget
50
- - ` allowEmptyList ` * boolean* : whether to allow the empty list
51
- - ` columns ` * array* : the row columns configuration where you can set the following properties:
52
- - ` name ` * string* : input name. * Required options*
53
- - ` type ` * string* : type of the input. If not set will default to ` textInput ` . Read more about the types described below
54
- - ` title ` * string* : the column title
55
- - ` value ` * Closure* : you can set it to an anonymous function with the following signature: ``` function($data) {} ```
56
- - ` defaultValue ` * string* : default value of input,
57
- - ` items ` * array* |* Closure* : the items for input with type dropDownList, listBox, checkboxList, radioList or anonymous function
58
- which return array of items and has the following signature: ``` function($data) {} ```
59
- - ` options ` * array* : the HTML attributes for the input
60
- - ` headerOptions ` * array* : the HTML attributes for the header cell
61
- - ` enableError ` * boolean* : whether to render inline error for the input. Default to ` false `
62
- - ` errorOptions ` * array* : the HTMl attributes for the error tag
51
+
52
+ ** addButtonPosition** * integer* : the position of ` add ` button. This can be MultipleInput::POS_HEADER or MultipleInput::POS_ROW.
53
+
54
+ ** addButtonOptions** * array* : the HTML options for ` add ` button. Can contains ` class ` and ` label ` keys
55
+
56
+ ** removeButtonOptions** * array* : the HTML options for ` add ` button. Can contains ` class ` and ` label ` keys
57
+
58
+ ** data** * array* : array of values in case you use widget without model
59
+
60
+ ** models** * array* : the list of models. Required in case you use ` TabularInput ` widget
61
+
62
+ ** allowEmptyList** * boolean* : whether to allow the empty list
63
+
64
+ ** columns** * array* : the row columns configuration where you can set the properties which is described below
65
+
66
+ ### Column options
67
+
68
+ ** name** * string* : input name. * Required options*
69
+
70
+ ** type** * string* : type of the input. If not set will default to ` textInput ` . Read more about the types described below
71
+
72
+ ** title** * string* : the column title
73
+
74
+ ** value** * Closure* : you can set it to an anonymous function with the following signature:
75
+
76
+ ``` php
77
+ function($data) {}
78
+ ```
79
+
80
+ ** defaultValue** * string* : default value of input
81
+
82
+ ** items** * array* |* Closure* : the items for input with type dropDownList, listBox, checkboxList, radioList
83
+ or anonymous function which return array of items and has the following signature:
84
+
85
+ ``` php
86
+ function($data) {}
87
+ ```
88
+
89
+ ** options** * array* : the HTML attributes for the input
90
+
91
+ ** headerOptions** * array* : the HTML attributes for the header cell
92
+
93
+ ** enableError** * boolean* : whether to render inline error for the input. Default to ` false `
94
+
95
+ ** errorOptions** * array* : the HTMl attributes for the error tag
63
96
64
97
### Input types
65
98
@@ -101,8 +134,13 @@ use unclead\widgets\MultipleInput;
101
134
102
135
...
103
136
104
- <?= $form->field($model, 'emails')->widget(MultipleInput::className(), [
105
- 'limit' => 5
137
+ <?php
138
+ echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
139
+ 'limit' => 6,
140
+ 'allowEmptyList' => false,
141
+ 'enableGuessTitle' => true,
142
+ 'min' => 2, // should be at least 2 rows
143
+ 'addButtonPosition' => MultipleInput::POS_HEADER // show add button in the header
106
144
])
107
145
->label(false);
108
146
?>
@@ -280,6 +318,8 @@ In some cases you need to have the ability to delete all rows in the list. For t
280
318
281
319
```
282
320
321
+ Also you can set ` 0 ` in ` min ` option if you don't need first blank row when data is empty.
322
+
283
323
### Guess column title
284
324
285
325
Sometimes you can use the widget without defining columns but you want to have the column header of the table.
0 commit comments