From 6ca70bd8bca6b29c481323c75c4e7787c8fc3906 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Tue, 14 Sep 2021 08:10:19 -0400 Subject: [PATCH] Fix multiline validation (#1658) --- src/Form/Control/Multiline.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Form/Control/Multiline.php b/src/Form/Control/Multiline.php index 1821ad2056..a226d3fdc6 100644 --- a/src/Form/Control/Multiline.php +++ b/src/Form/Control/Multiline.php @@ -308,26 +308,26 @@ public function getValue(): string public function validate(array $rows): array { $rowErrors = []; - $model = $this->getModel(); + $entity = $this->getModel()->createEntity(); foreach ($rows as $cols) { $rowId = $this->getMlRowId($cols); foreach ($cols as $fieldName => $value) { - if ($fieldName === '__atkml' || $fieldName === $model->id_field) { + if ($fieldName === '__atkml' || $fieldName === $entity->id_field) { continue; } try { - $field = $model->getField($fieldName); + $field = $entity->getField($fieldName); // Save field value only if the field was editable if (!$field->read_only) { - $model->createEntity()->set($fieldName, $value); + $entity->set($fieldName, $value); } } catch (\Atk4\Core\Exception $e) { $rowErrors[$rowId][] = ['name' => $fieldName, 'msg' => $e->getMessage()]; } } - $rowErrors = $this->addModelValidateErrors($rowErrors, $rowId, $model); + $rowErrors = $this->addModelValidateErrors($rowErrors, $rowId, $entity); } return $rowErrors; @@ -373,12 +373,12 @@ public function saveRows(): self /** * Check for model validate error. */ - protected function addModelValidateErrors(array $errors, string $rowId, Model $model): array + protected function addModelValidateErrors(array $errors, string $rowId, Model $entity): array { - $e = $model->validate(); - if ($e) { - foreach ($e as $field => $msg) { - $errors[$rowId][] = ['field' => $field, 'msg' => $msg]; + $entityErrors = $entity->validate(); + if ($entityErrors) { + foreach ($entityErrors as $fieldName => $msg) { + $errors[$rowId][] = ['name' => $fieldName, 'msg' => $msg]; } }