From 2e1bab30254fab4ba425ab15ce3d389038ed6dee Mon Sep 17 00:00:00 2001 From: Oleg Baturin Date: Wed, 25 Aug 2021 19:07:45 +0700 Subject: [PATCH 1/3] #347 separate input name generator method from error field name generator --- src/MultipleInputColumn.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/MultipleInputColumn.php b/src/MultipleInputColumn.php index e92c20c..01e593c 100644 --- a/src/MultipleInputColumn.php +++ b/src/MultipleInputColumn.php @@ -49,12 +49,10 @@ public function getElementName($index, $withPrefix = true) $index = '{' . $this->renderer->getIndexPlaceholder() . '}'; } - $elementName = $this->isRendererHasOneColumn() - ? '[' . $this->name . '][' . $index . ']' - : '[' . $index . '][' . $this->name . ']'; - - if (!$withPrefix) { - return $elementName; + if ($this->isRendererHasOneColumn() && $this->hasModelAttribute($this->name)) { + $elementName = '[' . $index . ']'; + } else { + $elementName = '[' . $index . '][' . $this->name . ']'; } $prefix = $this->getInputNamePrefix(); @@ -87,7 +85,7 @@ protected function getInputNamePrefix() $model = $this->context->model; if ($model instanceof Model) { if (empty($this->renderer->columns) || ($this->isRendererHasOneColumn() && $this->hasModelAttribute($this->name))) { - return $model->formName(); + return Html::getInputName($this->context->model, $this->name); } return Html::getInputName($this->context->model, $this->context->attribute); @@ -128,7 +126,7 @@ public function getFirstError($index) if ($this->isRendererHasOneColumn()) { $attribute = $this->name . '[' . $index . ']'; } else { - $attribute = $this->context->attribute . $this->getElementName($index, false); + $attribute = $this->context->attribute . '[' . $index . '][' . $this->name . ']'; } $model = $this->context->model; From 451386bfc3ebf2017de989eb2337e4b784b15321 Mon Sep 17 00:00:00 2001 From: Oleg Baturin Date: Wed, 25 Aug 2021 19:24:36 +0700 Subject: [PATCH 2/3] update condition for error field name --- src/MultipleInputColumn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MultipleInputColumn.php b/src/MultipleInputColumn.php index 01e593c..bf30691 100644 --- a/src/MultipleInputColumn.php +++ b/src/MultipleInputColumn.php @@ -123,7 +123,7 @@ public function getFirstError($index) return null; } - if ($this->isRendererHasOneColumn()) { + if ($this->isRendererHasOneColumn() && $this->hasModelAttribute($this->name)) { $attribute = $this->name . '[' . $index . ']'; } else { $attribute = $this->context->attribute . '[' . $index . '][' . $this->name . ']'; From 71e4c3ff025242081faeba101ad2dac06f654fd6 Mon Sep 17 00:00:00 2001 From: Oleg Baturin Date: Thu, 26 Aug 2021 19:39:50 +0700 Subject: [PATCH 3/3] fix case with no columns --- src/MultipleInputColumn.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MultipleInputColumn.php b/src/MultipleInputColumn.php index bf30691..dd0250c 100644 --- a/src/MultipleInputColumn.php +++ b/src/MultipleInputColumn.php @@ -49,7 +49,7 @@ public function getElementName($index, $withPrefix = true) $index = '{' . $this->renderer->getIndexPlaceholder() . '}'; } - if ($this->isRendererHasOneColumn() && $this->hasModelAttribute($this->name)) { + if (empty($this->renderer->columns) || ($this->isRendererHasOneColumn() && $this->hasModelAttribute($this->name))) { $elementName = '[' . $index . ']'; } else { $elementName = '[' . $index . '][' . $this->name . ']'; @@ -123,7 +123,7 @@ public function getFirstError($index) return null; } - if ($this->isRendererHasOneColumn() && $this->hasModelAttribute($this->name)) { + if (empty($this->renderer->columns) || ($this->isRendererHasOneColumn() && $this->hasModelAttribute($this->name))) { $attribute = $this->name . '[' . $index . ']'; } else { $attribute = $this->context->attribute . '[' . $index . '][' . $this->name . ']';