Skip to content

Commit 4cee01b

Browse files
committed
Correct processing of embedded MultipleInout widgets with nesting level 2 ad more
1 parent 36aecfe commit 4cee01b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/MultipleInputColumn.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,18 @@ public function getFirstError($index)
129129
protected function renderWidget($type, $name, $value, $options)
130130
{
131131
// Extend options in case of rendering embedded MultipleInput
132-
// We have to pass to the widget original model and attribute to be able get first error from model
132+
// We have to pass to the widget an original model and an attribute to be able get a first error from model
133133
// for embedded widget.
134134
if ($type === MultipleInput::class && strpos($name, $this->renderer->getIndexPlaceholder()) === false) {
135135
$model = $this->context->model;
136136

137-
$search = sprintf('%s[%s]', $model->formName(), $this->context->attribute);
137+
// in case of embedding level 2 and more
138+
if (preg_match('/^([\w\.]+)(\[.*)$/', $this->context->attribute, $matches)) {
139+
$search = sprintf('%s[%s]%s', $model->formName(), $matches[1], $matches[2]);
140+
} else {
141+
$search = sprintf('%s[%s]', $model->formName(), $this->context->attribute);
142+
}
143+
138144
$replace = $this->context->attribute;
139145

140146
$attribute = str_replace($search, $replace, $name);

0 commit comments

Comments
 (0)