Skip to content

Commit 3d4895c

Browse files
author
Eugene Tupikov
committed
replace the widget placeholder in all nested options
1 parent 753e7be commit 3d4895c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/components/BaseColumn.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use yii\helpers\ArrayHelper;
1919
use yii\helpers\Html;
2020
use yii\helpers\Inflector;
21+
use yii\helpers\Json;
2122
use unclead\multipleinput\renderers\BaseRenderer;
2223

2324
/**
@@ -317,6 +318,18 @@ public function renderInput($name, $options, $contextParams = [])
317318
$options = ArrayHelper::merge($options, $optionsExt);
318319
$method = 'render' . Inflector::camelize($this->type);
319320

321+
// @see https://github.com/unclead/yii2-multiple-input/issues/261
322+
// we have to replace placeholder in all nested options and the best way to do it is:
323+
// 1) encode the options to a json string
324+
// 2) replace the placeholder
325+
// 3) decode the json string back to array
326+
// But we have to leave the placeholder in case of processing a row template
327+
if ($contextParams['index'] !== null) {
328+
$options_string = Json::encode($options);
329+
$options_string = str_replace('{' . $contextParams['indexPlaceholder'] . '}', $contextParams['index'], $options_string);
330+
$options = Json::decode($options_string);
331+
}
332+
320333
$value = null;
321334
if ($this->type !== self::TYPE_DRAGCOLUMN) {
322335
$value = $this->prepareValue($contextParams);

src/renderers/TableRenderer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ public function renderCellContent($column, $index, $columnIndex = null)
281281
if (substr($id, -4) === 'drag') {
282282
$options = ArrayHelper::merge($options, ['class' => $this->iconMap['drag-handle']]);
283283
}
284+
284285
$input = $column->renderInput($name, $options, [
285286
'id' => $id,
286287
'name' => $name,

0 commit comments

Comments
 (0)