Skip to content

Commit 490412d

Browse files
Eugene Tupikovgitbook-bot
authored andcommitted
GitBook: [master] 10 pages modified
1 parent c0c1ef6 commit 490412d

10 files changed

+1187
-46
lines changed

README.md

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,18 @@
1-
# Yii2 Multiple input widget.
2-
Yii2 widget for handle multiple inputs for an attribute of model and tabular input for batch of models.
1+
# Installation
32

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-
[![Daily Downloads](https://poser.pugx.org/unclead/yii2-multiple-input/d/daily)](https://packagist.org/packages/unclead/yii2-multiple-input)
7-
[![Latest Unstable Version](https://poser.pugx.org/unclead/yii2-multiple-input/v/unstable)](https://packagist.org/packages/unclead/yii2-multiple-input)
8-
[![License](https://poser.pugx.org/unclead/yii2-multiple-input/license)](https://packagist.org/packages/unclead/yii2-multiple-input)
9-
10-
## Latest release
11-
The latest stable version of the extension is v2.25.0 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
12-
13-
## Installation
143
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
154

165
Either run
176

18-
```
7+
```text
198
php composer.phar require unclead/yii2-multiple-input "~2.0"
209
```
2110

2211
or add
2312

24-
```
13+
```text
2514
"unclead/yii2-multiple-input": "~2.0"
2615
```
2716

28-
to the require section of your `composer.json` file.
29-
30-
## Basic usage
31-
32-
![Single column example](./resources/images/single-column.gif?raw=true)
33-
34-
For example you want to have an ability of entering several emails of user on profile page.
35-
In this case you can use yii2-multiple-input widget like in the following code
36-
37-
```php
38-
use unclead\multipleinput\MultipleInput;
39-
40-
...
41-
42-
<?php
43-
echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
44-
'max' => 6,
45-
'min' => 2, // should be at least 2 rows
46-
'allowEmptyList' => false,
47-
'enableGuessTitle' => true,
48-
'addButtonPosition' => MultipleInput::POS_HEADER, // show add button in the header
49-
])
50-
->label(false);
51-
?>
52-
```
53-
54-
## Documentation
55-
56-
You can find a full version of documentation [here](https://unclead.gitbook.io/yii2-multiple-input/)
57-
58-
## License
17+
to the `require`section of your `composer.json` file.
5918

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

SUMMARY.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Table of contents
2+
3+
* [Installation](README.md)
4+
* [Getting started](getting-started.md)
5+
* [Usage](usage.md)
6+
* [Configuration](configuration.md)
7+
* [Javascript events](javascript-events.md)
8+
* [Using other icon libraries](using-other-icon-libraries.md)
9+
* [Renderers](renderers.md)
10+
* [Clonning](clonning.md)
11+
* [Tips and tricks](tips-and-tricks.md)
12+

clonning.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Clonning
2+
3+
![Clone button example](https://raw.githubusercontent.com/unclead/yii2-multiple-input/master/resources/images/clone-button.gif)
4+
5+
```text
6+
use unclead\multipleinput\MultipleInput;
7+
8+
...
9+
10+
$form->field($model, 'products')->widget(MultipleInput::className(), [
11+
'max' => 10,
12+
'cloneButton' => true,
13+
'columns' => [
14+
[
15+
'name' => 'product_id',
16+
'type' => 'dropDownList',
17+
'title' => 'Special Products',
18+
'defaultValue' => 1,
19+
'items' => [
20+
1 => 'id: 1, price: $19.99, title: product1',
21+
2 => 'id: 2, price: $29.99, title: product2',
22+
3 => 'id: 3, price: $39.99, title: product3',
23+
4 => 'id: 4, price: $49.99, title: product4',
24+
5 => 'id: 5, price: $59.99, title: product5',
25+
],
26+
],
27+
[
28+
'name' => 'time',
29+
'type' => DateTimePicker::className(),
30+
'title' => 'due date',
31+
'defaultValue' => date('d-m-Y h:i')
32+
],
33+
[
34+
'name' => 'count',
35+
'title' => 'Count',
36+
'defaultValue' => 1,
37+
'enableError' => true,
38+
'options' => [
39+
'type' => 'number',
40+
'class' => 'input-priority',
41+
]
42+
]
43+
]
44+
])->label(false);
45+
```
46+
47+
48+

configuration.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Configuration
2+
3+
Widget support the following options that are additionally recognized over and above the configuration options in the InputWidget.
4+
5+
## Base options
6+
7+
**theme** _string_: specify the theme of the widget. Available 2 themes:
8+
9+
* `default` with only widget css classes
10+
* `bs` \(twitter bootstrap\) theme with additional BS ccs classes\).
11+
12+
Default value is `bs`
13+
14+
**max** _integer_: maximum number of rows. If not set will default to unlimited
15+
16+
**min** _integer_: minimum number of rows. Set to `0` if you need the empty list in case you don't have any data
17+
18+
**prepend** _boolean_: add a new row to the beginning of the list, not to the end
19+
20+
**attributeOptions** _array_: client-side attribute options, e.g. enableAjaxValidation. You may use this property in case when you use widget without a model, since in this case widget is not able to detect client-side options automatically
21+
22+
**addButtonPosition** _integer\|array_: the position\(s\) of `add` button. This can be `MultipleInput::POS_HEADER`, `MultipleInput::POS_ROW`, `MultipleInput::POS_ROW_BEGIN` or `MultipleInput::POS_FOOTER`.
23+
24+
**addButtonOptions** _array_: the HTML options for `add` button. Can contains `class` and `label` keys
25+
26+
**removeButtonOptions** _array_: the HTML options for `remove` button. Can contains `class` and `label` keys
27+
28+
**data** _array_: array of values in case you use widget without model
29+
30+
**models** _array_: the list of models. Required in case you use `TabularInput` widget
31+
32+
**allowEmptyList** _boolean_: whether to allow the empty list
33+
34+
**columnClass** _string_: the name of column class. You can specify your own class to extend base functionality. Defaults to `unclead\multipleinput\MultipleInputColumn` for `MultipleInput` and `unclead\multipleinput\TabularColumn` for `TabularInput`.
35+
36+
**rendererClass** _string_: the name of renderer class. You can specify your own class to extend base functionality. Defaults to `unclead\multipleinput\renderers\TableRenderer`.
37+
38+
**columns** _array_: the row columns configuration where you can set the properties which is described below
39+
40+
**rowOptions** _array\|\Closure_: the HTML attributes for the table body rows. This can be either an array specifying the common HTML attributes for all body rows, or an anonymous function that returns an array of the HTML attributes. It should have the following signature:
41+
42+
```php
43+
function ($model, $index, $context)
44+
```
45+
46+
* `$model`: the current data model being rendered
47+
* `$index`: the zero-based index of the data model in the model array
48+
* `$context`: the widget object
49+
50+
**sortable** _bool_: whether need to enable sorting or not
51+
52+
**modelClass** _string_: a class of model which is used to render `TabularInput`. You must specify this property when a list of `models` is empty. If this property is not specified the widget will detect it based on a class of `models`
53+
54+
**cloneButton** _bool_: whether need to enable clone buttons or not
55+
56+
**extraButtons** _string\|\Closure_: the HTML content that will be rendered after the buttons. It can be either string or an anonymous function that returns a string which will be treated as HTML content. It should have the following signature:
57+
58+
```php
59+
function ($model, $index, $context)
60+
```
61+
62+
* `$model`: the current data model being rendered
63+
* `$index`: the zero-based index of the data model in the model array
64+
* `$context`: the MultipleInput widget object
65+
66+
**layoutConfig** _array_: CSS grid classes for horizontal layout \(only supported for `ListRenderer` class\). This must be an array with these keys:
67+
68+
* `'offsetClass'`: the offset grid class to append to the wrapper if no label is rendered
69+
* `'labelClass'`: the label grid class
70+
* `'wrapperClass'`: the wrapper grid class
71+
* `'errorClass'`: the error grid class
72+
73+
**showGeneralError** _bool_: whether need to show error message for main attribute, when you don't want to validate particular input and want to validate a filed in general.
74+
75+
## Column options
76+
77+
**name** _string_: input name. _Required options_
78+
79+
**type** _string_: type of the input. If not set will default to `textInput`. Read more about the types described below
80+
81+
**title** _string_: the column title
82+
83+
**value** _Closure_: you can set it to an anonymous function with the following signature:
84+
85+
```php
86+
function($data) {}
87+
```
88+
89+
**defaultValue** _string_: default value of input
90+
91+
**items** _array_\|_Closure_: the items for input with type dropDownList, listBox, checkboxList, radioList or anonymous function which return array of items and has the following signature:
92+
93+
```php
94+
function($data) {}
95+
```
96+
97+
**options** _array_\|_Closure_: the HTML attributes for the input, you can set it as array or an anonymous function with the following signature:
98+
99+
```php
100+
function($data) {}
101+
```
102+
103+
**headerOptions** _array_: the HTML attributes for the header cell
104+
105+
**enableError** _boolean_: whether to render inline error for the input. Default to `false`
106+
107+
**errorOptions** _array_: the HTMl attributes for the error tag
108+
109+
**nameSuffix** _string_: the unique prefix for attribute's name to avoid id duplication e.g. in case of using several copies of the widget on a page and one column is a Select2 widget
110+
111+
**tabindex** _integer_: use it to customize a form element `tabindex`
112+
113+
## Input types
114+
115+
Each column in a row can has their own type. Widget supports:
116+
117+
* all yii2 html input types:
118+
* `textInput`
119+
* `dropDownList`
120+
* `radioList`
121+
* `textarea`
122+
* For more detail look at [Html helper class](http://www.yiiframework.com/doc-2.0/yii-helpers-html.html)
123+
* input widget \(widget that extends from `InputWidget` class\). For example, `yii\widgets\MaskedInput`
124+
* `static` to output a static HTML content
125+
126+
For using widget as column input you may use the following code:
127+
128+
```php
129+
echo $form->field($model, 'phones')->widget(MultipleInput::className(), [
130+
...
131+
'columns' => [
132+
...
133+
[
134+
'name' => 'phones',
135+
'title' => $model->getAttributeLabel('phones'),
136+
'type' => \yii\widgets\MaskedInput::className(),
137+
'options' => [
138+
'class' => 'input-phone',
139+
'mask' => '999-999-99-99',
140+
],
141+
],
142+
],
143+
])->label(false);
144+
```
145+

0 commit comments

Comments
 (0)