Skip to content

Commit 53b925a

Browse files
committed
Merge remote-tracking branch 'origin/master' into dev-2.0
2 parents 53521f8 + a08491f commit 53b925a

File tree

7 files changed

+20
-5
lines changed

7 files changed

+20
-5
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+
1.4.1
5+
=====
6+
7+
- #99: Respect "defaultValue" if it is set and current value is empty (unclead)
8+
49
1.4.0
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 v1.4.0 Follow the [instruction](./UPGRADE.md) for upgrading from previous versions
11+
The latest stable version of the extension is v1.4.1 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": "1.4.0",
12+
"version": "1.4.1",
1313
"license": "BSD-3-Clause",
1414
"support": {
1515
"issues": "https://github.com/unclead/yii2-multiple-input/issues?state=open",

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> You can find source code of examples [here](./examples/)
44
55
- [One column](#one-column)
6-
- [Multiple columns](#multiple-columns-example)
6+
- [Multiple columns](#multiple-columns)
77
- [Tabular input](#tabular-input)
88

99
##One column

examples/views/tabular-input.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'name' => 'title',
3737
'title' => 'Title',
3838
'type' => TabularColumn::TYPE_TEXT_INPUT,
39+
'defaultValue' => 'Test',
3940
'enableError' => true
4041
],
4142
[

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

src/components/BaseColumn.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ protected function prepareValue()
180180
if ($this->value instanceof \Closure) {
181181
$value = call_user_func($this->value, $data);
182182
} else {
183+
$value = null;
183184
if ($data instanceof ActiveRecordInterface ) {
184185
$value = $data->getAttribute($this->name);
185186
} elseif ($data instanceof Model) {
@@ -188,13 +189,20 @@ protected function prepareValue()
188189
$value = ArrayHelper::getValue($data, $this->name, null);
189190
} elseif(is_string($data) || is_numeric($data)) {
190191
$value = $data;
191-
}else {
192+
}
193+
194+
if ($this->isEmpty($value) && $this->defaultValue !== null) {
192195
$value = $this->defaultValue;
193196
}
194197
}
195198
return $value;
196199
}
197200

201+
protected function isEmpty($value)
202+
{
203+
return $value === null || $value === [] || $value === '';
204+
}
205+
198206
/**
199207
* Returns element id.
200208
*
@@ -469,6 +477,7 @@ protected function renderWidget($type, $name, $value, $options)
469477
{
470478
$model = $this->getModel();
471479
if ($model instanceof Model) {
480+
$model->{$this->name} = $value;
472481
$widgetOptions = [
473482
'model' => $model,
474483
'attribute' => $this->name,

0 commit comments

Comments
 (0)