Skip to content

Commit a3f01dd

Browse files
committed
Merge pull request #24 from unclead/refactoring
Implemented of ability to use widget for tabular input
2 parents 5de6f20 + 04a1a3f commit a3f01dd

18 files changed

+1493
-600
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
Yii2 multiple input change log
22
==============================
33

4-
1.1.1 under development
5-
-----------------------
4+
1.2.0
5+
-----
66

7-
- Bug #19 refactoring rendering of inputs (unclead)
8-
- Bug #20 add hasAttribute checking for AR models (unclead)
7+
- Bug #19 Refactoring rendering of inputs (unclead)
8+
- Bug #20 Added hasAttribute checking for AR models (unclead)
9+
- Enh #22 Added `TabularInput` widget (unclead), rendering logic has been moved to separate class (renderer)
910

1011
1.1.0
1112
-----

README.md

Lines changed: 138 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#Yii2 Multiple input widget.
22
Yii2 widget for handle multiple inputs for an attribute of model
33

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)
58

69
##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)
819

920
##Installation
1021
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
@@ -23,6 +34,53 @@ or add
2334

2435
to the require section of your `composer.json` file.
2536

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+
2684
##Usage
2785

2886
### Input with one column
@@ -35,14 +93,16 @@ In this case you can use yii2-multiple-input widget like in the following code
3593
```php
3694
use unclead\widgets\MultipleInput;
3795

96+
...
97+
3898
<?= $form->field($model, 'emails')->widget(MultipleInput::className(), [
3999
'limit' => 5
40100
])
41101
->label(false);
42102
?>
43103
```
44104

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)
46106

47107
### Input with multiple column in each row
48108

@@ -53,8 +113,10 @@ For example you keep some data in json format in attribute of model. Imagine tha
53113
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
54114

55115
```php
56-
57116
use unclead\widgets\MultipleInput;
117+
118+
...
119+
58120
<?= $form->field($model, 'schedule')->widget(MultipleInput::className(), [
59121
'limit' => 4,
60122
'columns' => [
@@ -113,54 +175,67 @@ use unclead\widgets\MultipleInput;
113175
?>
114176
```
115177

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)
117179

118-
> Also you can find source code of examples [here](./docs/examples/)
119-
120-
## Configuration
180+
### Tabular input
121181

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:
150184

151185
```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+
]) ?>
161232
```
162233

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
164239
This widget has following events:
165240
- `afterInit`: triggered after initialization
166241
- `afterAddRow`: triggered after new row insertion
@@ -169,11 +244,26 @@ This widget has following events:
169244

170245
Example:
171246
```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');
174258
});
175259
```
176260

261+
##Renderers
262+
263+
> Section is under development
264+
265+
Currently widget supports only `TableRenderer` which renders content in table format.
266+
177267
##License
178268

179269
**yii2-multiple-input** is released under the BSD 3-Clause License. See the bundled [LICENSE.md](./LICENSE.md) for details.

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
"yii2",
66
"yii2 multiple input",
77
"yii2 array input",
8-
"yii2 multiple field"
8+
"yii2 multiple field",
9+
"yii2 tabular input"
910
],
1011
"type": "yii2-extension",
11-
"version": "1.1.0",
12+
"version": "1.2.0",
1213
"license": "BSD-3-Clause",
1314
"support": {
1415
"issues": "https://github.com/unclead/yii2-multiple-input/issues?state=open",
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)