1
1
#Yii2 Multiple input widget.
2
2
Yii2 widget for handle multiple inputs for an attribute of model
3
3
4
- [ ![ Latest Stable Version] ( https://poser.pugx.org/unclead/yii2-multiple-input/v/stable )] ( https://packagist.org/packages/unclead/yii2-multiple-input ) [ ![ Total Downloads] ( https://poser.pugx.org/unclead/yii2-multiple-input/downloads )] ( https://packagist.org/packages/unclead/yii2-multiple-input ) [ ![ Latest Unstable Version] ( https://poser.pugx.org/unclead/yii2-multiple-input/v/unstable )] ( https://packagist.org/packages/unclead/yii2-multiple-input ) [ ![ License] ( https://poser.pugx.org/unclead/yii2-multiple-input/license )] ( https://packagist.org/packages/unclead/yii2-multiple-input )
4
+ [ ![ Latest Stable Version] ( https://poser.pugx.org/unclead/yii2-multiple-input/v/stable )] ( https://packagist.org/packages/unclead/yii2-multiple-input )
5
+ [ ![ Total Downloads] ( https://poser.pugx.org/unclead/yii2-multiple-input/downloads )] ( https://packagist.org/packages/unclead/yii2-multiple-input )
6
+ [ ![ Latest Unstable Version] ( https://poser.pugx.org/unclead/yii2-multiple-input/v/unstable )] ( https://packagist.org/packages/unclead/yii2-multiple-input )
7
+ [ ![ License] ( https://poser.pugx.org/unclead/yii2-multiple-input/license )] ( https://packagist.org/packages/unclead/yii2-multiple-input )
5
8
6
9
##Latest release
7
- The latest version of the extension is v1.1.0. Follow the [ instruction] ( ./UPGRADE.md ) for upgrading from previous versions
10
+ The latest version of the extension is v1.2.0. Follow the [ instruction] ( ./UPGRADE.md ) for upgrading from previous versions
11
+
12
+ Contents:
13
+
14
+ - [ Installation] ( #installation )
15
+ - [ Configuration] ( #configuration )
16
+ - [ Usage] ( #usage )
17
+ - [ Javascript Events] ( #javascript-events )
18
+ - [ Renderers] ( #renderers )
8
19
9
20
##Installation
10
21
The preferred way to install this extension is through [ composer] ( http://getcomposer.org/download/ ) .
@@ -23,6 +34,53 @@ or add
23
34
24
35
to the require section of your ` composer.json ` file.
25
36
37
+ ## Configuration
38
+
39
+ Widget support the following options that are additionally recognized over and above the configuration options in the InputWidget:
40
+
41
+ - ` limit ` : * integer* : rows limit. If not set will defaul to unlimited
42
+ - ` attributeOptions ` * array* : client-side attribute options, e.g. enableAjaxValidation. You may use this property in case when
43
+ you use widget without a model, since in this case widget is not able to detect client-side options automatically
44
+ - ` date ` * array* : array of values in case you use widget without model
45
+ - ` models ` * array* : the list of models. Required in case you use ` TabularInput ` widget
46
+ - ` columns ` * array* : the row columns configuration where you can set the following properties:
47
+ - ` name ` * string* : input name. * Required options*
48
+ - ` type ` * string* : type of the input. If not set will default to ` textInput ` . Read more about the types described below
49
+ - ` title ` * string* : the column title
50
+ - ` value ` * Closure* : you can set it to an anonymous function with the following signature: ``` function($data) {} ```
51
+ - ` defaultValue ` * string* : default value of input,
52
+ - ` items ` * array* : the items for input with type dropDownList, listBox, checkboxList, radioList
53
+ - ` options ` * array* : the HTML attributes for the input
54
+ - ` headerOptions ` * array* : the HTML attributes for the header cell
55
+ - ` enableError ` * boolean* : whether to render inline error for the input. Default to ` false `
56
+ - ` errorOptions ` * array* : the HTMl attributes for the error tag
57
+
58
+ ### Input types
59
+
60
+ Each column in a row can has their own type. Widget supports:
61
+
62
+ - all yii2 html input types:
63
+ - ` textInput `
64
+ - ` dropDownList `
65
+ - ` radioList `
66
+ - ` textarea `
67
+ - For more detail look at [ Html helper class] ( http://www.yiiframework.com/doc-2.0/yii-helpers-html.html )
68
+ - input widget (widget that extends from ` InputWidget ` class). For example, ` yii\widgets\MaskedInput `
69
+
70
+ For using widget as column input you may use the following code:
71
+
72
+ ``` php
73
+ [
74
+ 'name' => 'phone',
75
+ 'title' => 'Phone number',
76
+ 'type' => \yii\widgets\MaskedInput::className(),
77
+ 'options' => [
78
+ 'class' => 'input-phone',
79
+ 'mask' => '999-999-99-99'
80
+ ]
81
+ ]
82
+ ```
83
+
26
84
##Usage
27
85
28
86
### Input with one column
@@ -35,14 +93,16 @@ In this case you can use yii2-multiple-input widget like in the following code
35
93
``` php
36
94
use unclead\widgets\MultipleInput;
37
95
96
+ ...
97
+
38
98
<?= $form->field($model, 'emails')->widget(MultipleInput::className(), [
39
99
'limit' => 5
40
100
])
41
101
->label(false);
42
102
?>
43
103
```
44
104
45
- You can find more detail about this use case [ here] ( docs/single_column .md )
105
+ You can find more detail about this use case [ here] ( docs/multiple_input_single .md )
46
106
47
107
### Input with multiple column in each row
48
108
@@ -53,8 +113,10 @@ For example you keep some data in json format in attribute of model. Imagine tha
53
113
On the edit page you want to be able to manage this schedule and you can you yii2-multiple-input widget like in the following code
54
114
55
115
``` php
56
-
57
116
use unclead\widgets\MultipleInput;
117
+
118
+ ...
119
+
58
120
<?= $form->field($model, 'schedule')->widget(MultipleInput::className(), [
59
121
'limit' => 4,
60
122
'columns' => [
@@ -113,54 +175,67 @@ use unclead\widgets\MultipleInput;
113
175
?>
114
176
```
115
177
116
- You can find more detail about this use case [ here] ( docs/multiple_columns .md )
178
+ You can find more detail about this use case [ here] ( docs/multiple_input_multiple .md )
117
179
118
- > Also you can find source code of examples [ here] ( ./docs/examples/ )
119
-
120
- ## Configuration
180
+ ### Tabular input
121
181
122
- Widget support the following options that are additionally recognized over and above the configuration options in the InputWidget:
123
-
124
- - ` limit ` : * integer* : rows limit. If not set will defaul to unlimited
125
- - ` columns ` * array* : the row columns configuration where you can set the following properties:
126
- - ` name ` * string* : input name. * Required options*
127
- - ` type ` * string* : type of the input. If not set will default to ` textInput ` . Read more about the types described below
128
- - ` title ` * string* : the column title
129
- - ` value ` * Closure* : you can set it to an anonymous function with the following signature: ``` function($data) {} ```
130
- - ` defaultValue ` * string* : default value of input,
131
- - ` items ` * array* : the items for input with type dropDownList, listBox, checkboxList, radioList
132
- - ` options ` * array* : the HTML attributes for the input
133
- - ` headerOptions ` * array* : the HTML attributes for the header cell
134
- - ` enableError ` * boolean* : whether to render inline error for the input. Default to ` false `
135
- - ` errorOptions ` * array* : the HTMl attributes for the error tag
136
-
137
- ### Input types
138
-
139
- Each column in a row can has their own type. Widget supports:
140
-
141
- - all yii2 html input types:
142
- - ` textInput `
143
- - ` dropDownList `
144
- - ` radioList `
145
- - ` textarea `
146
- - For more detail look at [ Html helper class] ( http://www.yiiframework.com/doc-2.0/yii-helpers-html.html )
147
- - input widget (widget that extends from ` InputWidget ` class). For example, ` yii\widgets\MaskedInput `
148
-
149
- For using widget as column input you may use the following code:
182
+ For example you want to manage some models via tabular input. In this case you can use ` TabularInput ` widget which is based on ` MultipleInput ` widget.
183
+ Use the following code for this purpose:
150
184
151
185
``` php
152
- [
153
- 'name' => 'phone',
154
- 'title' => 'Phone number',
155
- 'type' => \yii\widgets\MaskedInput::className(),
156
- 'options' => [
157
- 'class' => 'input-phone',
158
- 'mask' => '999-999-99-99'
159
- ]
160
- ]
186
+ <?= TabularInput::widget([
187
+ 'models' => $models,
188
+ 'attributeOptions' => [
189
+ 'enableAjaxValidation' => true,
190
+ 'enableClientValidation' => false,
191
+ 'validateOnChange' => false,
192
+ 'validateOnSubmit' => true,
193
+ 'validateOnBlur' => false,
194
+ ],
195
+ 'columns' => [
196
+ [
197
+ 'name' => 'title',
198
+ 'title' => 'Title',
199
+ 'type' => \unclead\widgets\MultipleInputColumn::TYPE_TEXT_INPUT,
200
+ ],
201
+ [
202
+ 'name' => 'description',
203
+ 'title' => 'Description',
204
+ ],
205
+ [
206
+ 'name' => 'file',
207
+ 'title' => 'File',
208
+ 'type' => \vova07\fileapi\Widget::className(),
209
+ 'options' => [
210
+ 'settings' => [
211
+ 'url' => ['site/fileapi-upload']
212
+ ]
213
+ ]
214
+ ],
215
+ [
216
+ 'name' => 'date',
217
+ 'type' => \kartik\date\DatePicker::className(),
218
+ 'title' => 'Day',
219
+ 'options' => [
220
+ 'pluginOptions' => [
221
+ 'format' => 'dd.mm.yyyy',
222
+ 'todayHighlight' => true
223
+ ]
224
+ ],
225
+ 'headerOptions' => [
226
+ 'style' => 'width: 250px;',
227
+ 'class' => 'day-css-class'
228
+ ]
229
+ ],
230
+ ],
231
+ ]) ?>
161
232
```
162
233
163
- ### JavaScript events
234
+ You can find more detail about this use case [ here] ( docs/tabular_input.md )
235
+
236
+ > Also you can find source code of examples [ here] ( ./docs/examples/ )
237
+
238
+ ## JavaScript events
164
239
This widget has following events:
165
240
- ` afterInit ` : triggered after initialization
166
241
- ` afterAddRow ` : triggered after new row insertion
@@ -169,11 +244,26 @@ This widget has following events:
169
244
170
245
Example:
171
246
``` js
172
- jQuery (' #multiple-input' ).on (' afterAddRow' , function () {
173
- // some code
247
+ jQuery (' #multiple-input' ).on (' afterInit' , function (){
248
+ console .log (' calls on after initialization event' );
249
+ }).on (' beforeAddRow' , function (e ) {
250
+ console .log (' calls on before add row event' );
251
+ }).on (' afterAddRow' , function (e ) {
252
+ console .log (' calls on after add row event' );
253
+ }).on (' beforeDeleteRow' , function (){
254
+ console .log (' calls on before remove row event' );
255
+ return confirm (' Are you sure you want to delete row?' )
256
+ }).on (' afterDeleteRow' , function (){
257
+ console .log (' calls on after remove row event' );
174
258
});
175
259
```
176
260
261
+ ##Renderers
262
+
263
+ > Section is under development
264
+
265
+ Currently widget supports only ` TableRenderer ` which renders content in table format.
266
+
177
267
##License
178
268
179
269
** yii2-multiple-input** is released under the BSD 3-Clause License. See the bundled [ LICENSE.md] ( ./LICENSE.md ) for details.
0 commit comments