Yii2 widget for handle multiple inputs for an attribute of model and tabular input for batch of models.
The latest stable version of the extension is v2.10.0 Follow the instruction for upgrading from previous versions
The preferred way to install this extension is through composer.
Either run
php composer.phar require unclead/yii2-multiple-input "~2.0"
or add
"unclead/yii2-multiple-input": "~2.0"
to the require section of your composer.json
file.
For example you want to have an ability of entering several emails of user on profile page. In this case you can use yii2-multiple-input widget like in the following code
use unclead\multipleinput\MultipleInput;
...
<?php
echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
'max' => 6,
'min' => 2, // should be at least 2 rows
'allowEmptyList' => false,
'enableGuessTitle' => true,
'addButtonPosition' => MultipleInput::POS_HEADER // show add button in the header
])
->label(false);
?>
See more in single column
For example you want to have an interface for manage user schedule. For simplicity we will store the schedule in json string. In this case you can use yii2-multiple-input widget like in the following code
use unclead\multipleinput\MultipleInput;
...
<?= $form->field($model, 'schedule')->widget(MultipleInput::className(), [
'max' => 4,
'columns' => [
[
'name' => 'user_id',
'type' => 'dropDownList',
'title' => 'User',
'defaultValue' => 1,
'items' => [
1 => 'User 1',
2 => 'User 2'
]
],
[
'name' => 'day',
'type' => \kartik\date\DatePicker::className(),
'title' => 'Day',
'value' => function($data) {
return $data['day'];
},
'items' => [
'0' => 'Saturday',
'1' => 'Monday'
],
'options' => [
'pluginOptions' => [
'format' => 'dd.mm.yyyy',
'todayHighlight' => true
]
]
],
[
'name' => 'priority',
'title' => 'Priority',
'enableError' => true,
'options' => [
'class' => 'input-priority'
]
]
]
]);
?>
See more in multiple columns
You can find a full version of documentation in wiki
yii2-multiple-input is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.