From 73c62c8741ac6607c315b0354e7954dbe03a830e Mon Sep 17 00:00:00 2001 From: LeoZandvliet Date: Wed, 10 Jun 2020 10:03:35 +0200 Subject: [PATCH] Merge errors within same group If not merging the errors (on line 181/182), only the last message within a group is preserved. For example: ``` array('email', 'ext.validators.ConditionalValidator', 'if' => array( array('last_name', 'compare', 'compareValue' => '') ), 'then' => array( array('email', 'required', 'message' => 'Special email message'), array('phone_number', 'required', 'message' => 'Special phone number message'), ) ), ``` Now gives two seperate error messages. Before this change, only the last message, "Special phone number message" was preserved/shown. --- YiiConditionalValidator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/YiiConditionalValidator.php b/YiiConditionalValidator.php index 3d3c0fd..6c4648f 100644 --- a/YiiConditionalValidator.php +++ b/YiiConditionalValidator.php @@ -178,7 +178,8 @@ protected function runValidators(array $validatorsData, $discardErrorsAfterCheck $object->clearErrors(); if (!$discardErrorsAfterCheck) { - $object->addErrors($newErrors); + // Merge new with 'existing' errors to prevent the last error within the same group (if/then) overwrite all others + $object->addErrors(CMap::mergeArray($errorsBackup, $newErrors)); } if ($returnFalseOnError) {