Skip to content

Commit 0d61af5

Browse files
committed
Pass the added row to js event
1 parent ffb8ecc commit 0d61af5

File tree

7 files changed

+39
-38
lines changed

7 files changed

+39
-38
lines changed

CHANGELOG.md

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

4+
2.8.2
5+
=====
6+
7+
- Pass the added row to `afterAddRow` event
8+
49
2.8.1
510
=====
611

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Yii2 widget for handle multiple inputs for an attribute of model and tabular inp
88
[![License](https://poser.pugx.org/unclead/yii2-multiple-input/license)](https://packagist.org/packages/unclead/yii2-multiple-input)
99

1010
## Latest release
11-
The latest stable version of the extension is v2.8.1 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
11+
The latest stable version of the extension is v2.8.2 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
1212

1313
## Installation
1414
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"yii2 tabular input"
1010
],
1111
"type": "yii2-extension",
12-
"version": "2.8.1",
12+
"version": "2.8.2",
1313
"license": "BSD-3-Clause",
1414
"support": {
1515
"issues": "https://github.com/unclead/yii2-multiple-input/issues?state=open",

examples/views/multiple-input.php

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use unclead\multipleinput\examples\models\ExampleModel;
66
use yii\helpers\Html;
77
use unclead\multipleinput\MultipleInputColumn;
8-
use yii\widgets\MaskedInput;
98

109
// Note: You have to install https://github.com/kartik-v/yii2-widget-datepicker for correct work an example
1110
use kartik\date\DatePicker;
@@ -24,25 +23,25 @@
2423

2524
<h3>Single column</h3>
2625
<?php
27-
// echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
28-
// 'max' => 6,
29-
// 'allowEmptyList' => false,
30-
// 'columns' => [
31-
// [
32-
// 'name' => 'emails',
33-
// 'options' => [
34-
// 'placeholder' => 'E-mail'
35-
// ]
36-
// ]
37-
// ],
38-
// 'min' => 2, // should be at least 2 rows
39-
// 'addButtonPosition' => [
40-
// MultipleInput::POS_HEADER,
41-
// MultipleInput::POS_FOOTER,
42-
// MultipleInput::POS_ROW
43-
// ]
44-
// ])
45-
// ->label(false);
26+
echo $form->field($model, 'emails')->widget(MultipleInput::className(), [
27+
'max' => 6,
28+
'allowEmptyList' => false,
29+
'columns' => [
30+
[
31+
'name' => 'emails',
32+
'options' => [
33+
'placeholder' => 'E-mail'
34+
]
35+
]
36+
],
37+
'min' => 2, // should be at least 2 rows
38+
'addButtonPosition' => [
39+
MultipleInput::POS_HEADER,
40+
MultipleInput::POS_FOOTER,
41+
MultipleInput::POS_ROW
42+
]
43+
])
44+
->label(false);
4645
?>
4746

4847
<h3>Multiple columns</h3>
@@ -89,7 +88,7 @@
8988
],
9089
[
9190
'name' => 'day',
92-
'type' => MaskedInput::className(),
91+
'type' => DatePicker::className(),
9392
'title' => 'Day',
9493
'value' => function($data) {
9594
return $data['day'];
@@ -99,15 +98,11 @@
9998
'1' => 'Monday'
10099
],
101100
'options' => [
102-
'mask' => '99.99.9999'
103-
101+
'pluginOptions' => [
102+
'format' => 'dd.mm.yyyy',
103+
'todayHighlight' => true
104+
]
104105
],
105-
// 'options' => [
106-
// 'pluginOptions' => [
107-
// 'format' => 'dd.mm.yyyy',
108-
// 'todayHighlight' => true
109-
// ]
110-
// ],
111106
'headerOptions' => [
112107
'style' => 'width: 250px;',
113108
'class' => 'day-css-class'
@@ -164,8 +159,8 @@
164159
console.log('calls on after initialization event');
165160
}).on('beforeAddRow', function(e) {
166161
console.log('calls on before add row event');
167-
}).on('afterAddRow', function(e) {
168-
console.log('calls on after add row event');
162+
}).on('afterAddRow', function(e, row) {
163+
console.log('calls on after add row event', $(row));
169164
}).on('beforeDeleteRow', function(e, item){
170165
console.log(item);
171166
console.log('calls on before remove row event');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery.multipleInput",
3-
"version": "2.8.1",
3+
"version": "2.8.2",
44
"description": "jQuery multipleInput",
55
"scripts": {
66
"build": "npm install && (gulp || node node_modules/gulp/bin/gulp.js)"

src/assets/src/js/jquery.multipleInput.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* afterAddRow event is triggered after successful adding new row.
2424
* The signature of the event handler should be:
25-
* function (event)
25+
* function (event, row)
2626
* where event is an Event object.
2727
*
2828
*/
@@ -231,8 +231,9 @@
231231
}
232232

233233
template = template.replaceAll('{' + settings.indexPlaceholder + '}', data.currentIndex);
234+
var $addedInput = $(template);
234235

235-
$(template).hide().appendTo(inputList).fadeIn(300);
236+
$addedInput.hide().appendTo(inputList).fadeIn(300);
236237

237238
if (values instanceof Object) {
238239
var tmp = [];
@@ -290,7 +291,7 @@
290291
$wrapper.data('multipleInput').currentIndex++;
291292

292293
var event = $.Event(events.afterAddRow);
293-
$wrapper.trigger(event);
294+
$wrapper.trigger(event, [$addedInput]);
294295
};
295296

296297
var removeInput = function ($btn) {

src/assets/src/js/jquery.multipleInput.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)