Added ability to skip duplicate error messages and show all error messages in errorSummary.

Update CHANGELOG.md
This commit is contained in:
PowerGamer1
2016-08-18 15:16:23 +03:00
committed by SilverFire - Dmitry Naumenko
parent 26621fc3b1
commit 9e02e89fae
2 changed files with 14 additions and 2 deletions

View File

@ -8,6 +8,7 @@ Yii Framework 2 Change Log
- Bug #12428: Fixed `yii\db\mysql\QueryBuilder` causes warning when insert default rows into a table without primary key (DrmagicE)
- Enh #9989: ActiveForm now respects formtarget, formmethod and formenctype attributes of submit button (AnatolyRugalev)
- Enh #12296: Added value validation to `yii\log\Target::setLevels()` (Mak-Di)
- Enh #12193: Added the ability to suppress the generation of duplicate error messages in `Html::errorSummary`. Added the ability to display error messages beyond the first error for each model attribute (PowerGamer1)
- Enh #12073: Added the ability to suppress the generation of input hint when it is specified through `Model::attributeHints()` (PowerGamer1)
- Bug #7670: Added `UrlNormalizer` for normalizing requests with and without trailing slashes (rob006, cronfy, klimov-paul)
- Bug #9277: Fixed `yii\console\controllers\AssetController` looses custom options of 'target' bundles (petrabarus, klimov-paul)

View File

@ -1154,6 +1154,8 @@ class BaseHtml
* - header: string, the header HTML for the error summary. If not set, a default prompt string will be used.
* - footer: string, the footer HTML for the error summary.
* - encode: boolean, if set to false then the error messages won't be encoded.
* - showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise
* only the first error message for each attribute will be shown.
*
* The rest of the options will be rendered as the attributes of the container tag. The values will
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
@ -1164,6 +1166,7 @@ class BaseHtml
$header = isset($options['header']) ? $options['header'] : '<p>' . Yii::t('yii', 'Please fix the following errors:') . '</p>';
$footer = ArrayHelper::remove($options, 'footer', '');
$encode = ArrayHelper::remove($options, 'encode', true);
$showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false);
unset($options['header']);
$lines = [];
@ -1172,8 +1175,16 @@ class BaseHtml
}
foreach ($models as $model) {
/* @var $model Model */
foreach ($model->getFirstErrors() as $error) {
$lines[] = $encode ? Html::encode($error) : $error;
foreach ($model->getErrors() as $errors) {
foreach ($errors as $error) {
$line = $encode ? Html::encode($error) : $error;
if (array_search($line, $lines) === false) {
$lines[] = $line;
}
if (!$showAllErrors) {
break;
}
}
}
}