Skip to content

Commit 53b7381

Browse files
committed
Fixed #109 and #107
1 parent 8f02e28 commit 53b7381

File tree

10 files changed

+52
-15
lines changed

10 files changed

+52
-15
lines changed

CHANGELOG.md

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

4+
2.3.0
5+
=====
6+
7+
- #107: render a hidden input when `MultipleInput` is used for active field
8+
- #109: respect ID when using a widget's placeholder
9+
410
2.2.0
511
=====
612

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.2.0 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
11+
The latest stable version of the extension is v2.3.0 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.2.0",
12+
"version": "2.3.0",
1313
"license": "BSD-3-Clause",
1414
"support": {
1515
"issues": "https://github.com/unclead/yii2-multiple-input/issues?state=open",

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.2.0",
3+
"version": "2.3.0",
44
"description": "jQuery multipleInput",
55
"scripts": {
66
"build": "npm install && (gulp || node node_modules/gulp/bin/gulp.js)"

src/MultipleInput.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use yii\base\InvalidConfigException;
1313
use yii\base\Model;
1414
use yii\helpers\ArrayHelper;
15+
use yii\helpers\Html;
1516
use yii\widgets\ActiveForm;
1617
use yii\widgets\InputWidget;
1718
use yii\db\ActiveRecordInterface;
@@ -188,7 +189,15 @@ protected function guessColumns()
188189
*/
189190
public function run()
190191
{
191-
return $this->createRenderer()->render();
192+
$content = '';
193+
if ($this->hasModel()) {
194+
$content .= Html::hiddenInput(Html::getInputName($this->model, $this->attribute), null, [
195+
'id' => Html::getInputId($this->model, $this->attribute)
196+
]);
197+
}
198+
$content .= $this->createRenderer()->render();
199+
200+
return $content;
192201
}
193202

194203
/**
@@ -197,7 +206,7 @@ public function run()
197206
private function createRenderer()
198207
{
199208
$config = [
200-
'id' => $this->options['id'],
209+
'id' => $this->getId(),
201210
'columns' => $this->columns,
202211
'min' => $this->min,
203212
'max' => $this->max,

src/TabularInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function run()
147147
private function createRenderer()
148148
{
149149
$config = [
150-
'id' => $this->options['id'],
150+
'id' => $this->getId(),
151151
'columns' => $this->columns,
152152
'min' => $this->min,
153153
'max' => $this->max,

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,37 @@
4848
};
4949

5050
var defaultOptions = {
51+
/**
52+
* the ID of widget
53+
*/
5154
id: null,
52-
// the template of row
55+
/**
56+
* the ID of related input in case of using widget for an active field
57+
*/
58+
inputId: null,
59+
/**
60+
* the template of row
61+
*/
5362
template: null,
54-
// string that collect js templates of widgets which uses in the columns
63+
/**
64+
* string that collect js templates of widgets which uses in the columns
65+
*/
5566
jsTemplates: [],
56-
// how many row has to renders
67+
/**
68+
* how many row are allowed to render
69+
*/
5770
max: 1,
58-
// minimum number of rows
71+
/**
72+
* a minimum number of rows
73+
*/
5974
min: 1,
75+
/**
76+
* active form options of attributes
77+
*/
6078
attributes: {},
79+
/**
80+
* default prefix of a widget's placeholder
81+
*/
6182
indexPlaceholder: 'multiple_index'
6283
};
6384

@@ -73,7 +94,7 @@
7394
var settings = $.extend(true, {}, defaultOptions, options || {}),
7495
$wrapper = $('#' + settings.id),
7596
form = $wrapper.closest('form'),
76-
id = this.selector.replace('#', '');
97+
inputId = settings.inputId;
7798

7899
$wrapper.data('multipleInput', {
79100
settings: settings,
@@ -96,7 +117,7 @@
96117

97118
var intervalID = setInterval(function () {
98119
if (typeof form.data('yiiActiveForm') === 'object') {
99-
var attribute = form.yiiActiveForm('find', id),
120+
var attribute = form.yiiActiveForm('find', inputId),
100121
defaultAttributeOptions = {
101122
enableAjaxValidation: false,
102123
validateOnBlur: false,
@@ -113,7 +134,7 @@
113134
}
114135
});
115136

116-
form.yiiActiveForm('remove', id);
137+
form.yiiActiveForm('remove', inputId);
117138
}
118139

119140
// append default options to option from settings

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.

src/renderers/BaseRenderer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ protected function registerAssets()
289289

290290
$options = Json::encode([
291291
'id' => $this->id,
292+
'inputId' => $this->context->options['id'],
292293
'template' => $template,
293294
'jsTemplates' => $jsTemplates,
294295
'max' => $this->max,

src/renderers/TableRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function internalRender()
3939

4040
$content = Html::tag('table', implode("\n", $content), $options);
4141

42-
return Html::tag( 'div', $content, [
42+
return Html::tag('div', $content, [
4343
'id' => $this->id,
4444
'class' => 'multiple-input'
4545
]);

0 commit comments

Comments
 (0)