Skip to content

Commit

Permalink
Fix #148: Enhance EditableColumn to render unique ids for input widgets.
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Nov 21, 2014
1 parent 30ec05d commit 9eddf20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Version 2.6.0
=============
**Date:** 19-Nov-2014
**Date:** 20-Nov-2014

1. (enh #139): German translations updated.
2. (enh #140): French translations added.
Expand All @@ -11,6 +11,7 @@ Version 2.6.0
7. (enh #145): Enhance style to enable floated header wrapper tables to autofit/expand inside panel.
8. (bug #146): Create Spanish translations.
9. (bug #147): ActionColumn dropdownButton label changes value only for 1st row.
9. (bug #148): Enhance EditableColumn to render unique ids for input widgets.

#### BC Breaking Changes

Expand Down
16 changes: 15 additions & 1 deletion EditableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yii;
use Closure;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\base\InvalidConfigException;
use kartik\editable\Editable;
use kartik\base\Config;
Expand Down Expand Up @@ -54,6 +55,18 @@ public function init()
Config::checkDependency('editable\Editable', 'yii2-editable', 'for GridView EditableColumn');
}

/**
* Set array value only if key not set
* @param array $array
* @param mixed $key
* @param mixed $value
*/
protected static function setVal(&$array, $key, $val) {
if (empty($array[$key])) {
$array[$key] = $val;
}
}

/**
* Renders the data cell content.
* @param mixed $model the data model
Expand Down Expand Up @@ -84,7 +97,8 @@ public function renderDataCellContent($model, $key, $index)
if ($this->attribute !== null) {
$this->_editableOptions['model'] = $model;
$this->_editableOptions['attribute'] = $this->attribute;
$this->_editableOptions['options']['id'] = $this->attribute . "-" . $index;
$type = ArrayHelper::getValue($this->_editableOptions, 'inputType', Editable::INPUT_TEXT);
static::setVal($this->_editableOptions['options'], 'id', $this->attribute . "-" . $index);
} elseif (empty($this->_editableOptions['name']) && empty($this->_editableOptions['model']) ||
!empty($this->_editableOptions['model']) && empty($this->_editableOptions['attribute'])) {
throw new InvalidConfigException("You must setup the 'attribute' for your EditableColumn OR set one of 'name' OR 'model' & 'attribute' in 'editableOptions' (Exception at index: '{$index}', key: '{$strKey}').");
Expand Down

0 comments on commit 9eddf20

Please sign in to comment.