Skip to content

Commit 54653ce

Browse files
author
Eugene Tupikov
committed
improvements
1 parent 8ac7f9b commit 54653ce

File tree

8 files changed

+161
-66
lines changed

8 files changed

+161
-66
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
Yii2 multiple input change log
22
==============================
33

4-
1.0.5 under development
4+
1.1.1 under development
55
-----------------------
66

7-
- Bug #17 display inline errors (unclead, mikbox74)
7+
1.1.0
8+
-----
9+
10+
- Bug #17: display inline errors (unclead, mikbox74)
11+
- Enh #11: Improve js events (unclead)
12+
- Bug #16: correct use of defaultValue property (unclead)
13+
- code improvements (unclead)
814

915
1.0.4
1016
--------------------

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ Yii2 widget for handle multiple inputs for an attribute of model
33

44
[![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)
55

6-
##Installation
7-
6+
##Latest release
7+
The latest version of the extension is v1.1.0. Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
88

9+
##Installation
910
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
1011

1112
Either run
@@ -161,13 +162,14 @@ For using widget as column input you may use the following code:
161162

162163
### JavaScript events
163164
This widget has following events:
164-
- `init`: triggered after initialization
165-
- `addNewRow`: triggered after new row insertion
166-
- `removeRow`: triggered after row removal
165+
- `afterInit`: triggered after initialization
166+
- `afterAddRow`: triggered after new row insertion
167+
- `beforeDeleteRow`: triggered before the row removal
168+
- `afterDeleteRow`: triggered after the row removal
167169

168170
Example:
169171
```js
170-
jQuery('#multiple-input').on('addNewRow', function() {
172+
jQuery('#multiple-input').on('afterAddRow', function() {
171173
//some code
172174
});
173175
```

UPGRADE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Upgrading Instructions for yii2-multiple-widget
2+
===============================================
3+
4+
!!!IMPORTANT!!!
5+
6+
The following upgrading instructions are cumulative. That is,
7+
if you want to upgrade from version A to version C and there is
8+
version B between A and C, you need to following the instructions
9+
for both A and B.
10+
11+
Upgrade from version less then 1.1.0
12+
------------------------------------
13+
14+
After installing version 1.1.0 you have to rename js events following the next schema:
15+
16+
- Event `init` rename to `afterInit`
17+
- Event `addNewRow` rename to `afterAddRow`
18+
- Event `removeRow` rename to `afterDeleteRow`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"yii2 multiple field"
99
],
1010
"type": "yii2-extension",
11-
"version": "1.0.4",
11+
"version": "1.1.0",
1212
"license": "BSD-3-Clause",
1313
"support": {
1414
"issues": "https://github.com/unclead/yii2-multiple-input/issues?state=open",

examples/views/example.php

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,53 @@
44
use unclead\widgets\MultipleInput;
55
use unclead\widgets\examples\models\ExampleModel;
66
use yii\helpers\Html;
7+
use nex\chosen\Chosen;
8+
use unclead\widgets\MultipleInputColumn;
79

810
// Note: You have to install https://github.com/kartik-v/yii2-widget-datepicker for correct work an example
911
use kartik\date\DatePicker;
1012

11-
/* @var $this \yii\base\View */
13+
/* @var $this \yii\web\View */
1214
/* @var $model ExampleModel */
1315
?>
1416

1517
<?php $form = ActiveForm::begin([
1618
'enableAjaxValidation' => true,
19+
// 'enableAjaxValidation' => false,
1720
'enableClientValidation' => false,
1821
'validateOnChange' => false,
1922
'validateOnSubmit' => true,
2023
'validateOnBlur' => false,
2124
]);?>
2225

23-
<h3>Single column</h3>
26+
<h3>Single column</h3>
2427
<?php
25-
echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
26-
'limit' => 5
27-
])
28-
->label(false);
28+
// echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
29+
// 'limit' => 5
30+
// ])
31+
// ->label(false);
2932
?>
3033

31-
<h3>Multiple columns</h3>
34+
<h3>Multiple columns</h3>
3235
<?= $form->field($model, 'schedule')->widget(MultipleInput::className(), [
36+
'id' => 'schedule-wrapper',
3337
'limit' => 4,
3438
'columns' => [
3539
[
3640
'name' => 'user_id',
37-
'type' => 'dropDownList',
41+
'type' => MultipleInputColumn::TYPE_DROPDOWN,
42+
'enableError' => true,
3843
'title' => 'User',
39-
'defaultValue' => 1,
44+
'defaultValue' => 33,
4045
'items' => [
41-
1 => 'User 1',
42-
2 => 'User 2'
43-
]
46+
'' => 'Select user',
47+
31 => 'item 31',
48+
32 => 'item 32',
49+
33 => 'item 33',
50+
34 => 'item 34',
51+
35 => 'item 35',
52+
36 => 'item 36',
53+
],
4454
],
4555
[
4656
'name' => 'day',
@@ -67,6 +77,8 @@
6777
[
6878
'name' => 'priority',
6979
'title' => 'Priority',
80+
'defaultValue' => 1,
81+
'enableError' => true,
7082
'options' => [
7183
'class' => 'input-priority'
7284
]
@@ -80,9 +92,33 @@
8092
'headerOptions' => [
8193
'style' => 'width: 70px;',
8294
]
95+
],
96+
[
97+
'type' => 'checkbox',
98+
'name' => 'enable',
99+
'defaultValue' => 0
83100
]
84101
]
85-
]);
102+
]);
86103
?>
87104
<?= Html::submitButton('Update', ['class' => 'btn btn-success']);?>
88-
<?php ActiveForm::end();?>
105+
<?php ActiveForm::end();?>
106+
107+
108+
<?php
109+
$js = <<< JS
110+
$('#schedule-wrapper').on('afterInit', function(){
111+
console.log('calls on after initialization event');
112+
}).on('beforeAddRow', function(e) {
113+
console.log('calls on before add row event');
114+
}).on('afterAddRow', function(e) {
115+
console.log('calls on after add row event');
116+
}).on('beforeDeleteRow', function(){
117+
console.log('calls on before remove row event');
118+
return confirm('Are you sure you want to delete row?')
119+
}).on('afterDeleteRow', function(){
120+
console.log('calls on after remove row event');
121+
});
122+
JS;
123+
124+
$this->registerJs($js);

src/MultipleInput.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ class MultipleInput extends InputWidget
6262
*/
6363
protected $jsTemplates = [];
6464

65-
/**
66-
* @var string
67-
*/
68-
private $replacementKeys;
69-
7065
/**
7166
* Initialization.
7267
*
@@ -216,14 +211,7 @@ private function renderRowContent($index = null, $data = null)
216211
$hiddenInputs = [];
217212
foreach ($this->columns as $columnIndex => $column) {
218213
/* @var $column MultipleInputColumn */
219-
if (is_null($index)) {
220-
$value = 'multiple-' . $column->name . '-value';
221-
$this->replacementKeys[$value] = $column->defaultValue;
222-
$value = '{' . $value . '}';
223-
} else {
224-
$value = $column->prepareValue($data);
225-
}
226-
214+
$value = $column->prepareValue($data);
227215
if ($column->isHiddenInput()) {
228216
$hiddenInputs[] = $column->renderCellContent($value, $index);
229217
} else {
@@ -273,7 +261,7 @@ private function collectJsTemplates()
273261
private function renderActionColumn($index = null)
274262
{
275263
if (is_null($index)) {
276-
$action = '{multiple-btn-action}';
264+
$action = self::ACTION_REMOVE;
277265
$type = '{multiple-btn-type}';
278266
} else {
279267
$action = $index == 0 ? self::ACTION_ADD : self::ACTION_REMOVE;
@@ -368,10 +356,8 @@ public function registerClientScript()
368356
'id' => $this->getId(),
369357
'template' => $this->renderRowContent(),
370358
'jsTemplates' => $this->jsTemplates,
371-
'btnAction' => self::ACTION_REMOVE,
372359
'btnType' => 'btn-danger',
373360
'limit' => $this->limit,
374-
'replacement' => $this->replacementKeys,
375361
'attributeOptions' => $this->attributeOptions,
376362
]
377363
);

0 commit comments

Comments
 (0)