Merge pull request #20105 from skepticspriggan/19691-error-summary-always-visible-with-csp-header

Fix error summary always visible with CSP header (#19691)
This commit is contained in:
Bizley
2024-01-19 14:33:41 +01:00
committed by GitHub
3 changed files with 13 additions and 1 deletions

View File

@ -7,6 +7,7 @@ Yii Framework 2 Change Log
- Bug #17181: Improved `BaseUrl::isRelative($url)` performance (sammousa, bizley, rob006) - Bug #17181: Improved `BaseUrl::isRelative($url)` performance (sammousa, bizley, rob006)
- Bug #17191: Fixed `BaseUrl::isRelative($url)` method in `yii\helpers\BaseUrl` (ggh2e3) - Bug #17191: Fixed `BaseUrl::isRelative($url)` method in `yii\helpers\BaseUrl` (ggh2e3)
- Bug #18469: Fixed `Link::serialize(array $links)` method in `yii\web\Link` (ggh2e3) - Bug #18469: Fixed `Link::serialize(array $links)` method in `yii\web\Link` (ggh2e3)
- Bug #19691: Allow using custom class to style error summary (skepticspriggan)
- Bug #20040: Fix type `boolean` in `MSSQL` (terabytesoftw) - Bug #20040: Fix type `boolean` in `MSSQL` (terabytesoftw)
- Bug #20005: Fix `yii\console\controllers\ServeController` to specify the router script (terabytesoftw) - Bug #20005: Fix `yii\console\controllers\ServeController` to specify the router script (terabytesoftw)
- Bug #19060: Fix `yii\widgets\Menu` bug when using Closure for active item and adding additional tests in `tests\framework\widgets\MenuTest` (atrandafir) - Bug #19060: Fix `yii\widgets\Menu` bug when using Closure for active item and adding additional tests in `tests\framework\widgets\MenuTest` (atrandafir)

View File

@ -1260,6 +1260,7 @@ class BaseHtml
* - showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise * - 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. Defaults to `false`. * only the first error message for each attribute will be shown. Defaults to `false`.
* Option is available since 2.0.10. * Option is available since 2.0.10.
* - emptyClass: string, the class name that is added to an empty summary.
* *
* The rest of the options will be rendered as the attributes of the container tag. * The rest of the options will be rendered as the attributes of the container tag.
* *
@ -1271,12 +1272,17 @@ class BaseHtml
$footer = ArrayHelper::remove($options, 'footer', ''); $footer = ArrayHelper::remove($options, 'footer', '');
$encode = ArrayHelper::remove($options, 'encode', true); $encode = ArrayHelper::remove($options, 'encode', true);
$showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false); $showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false);
$emptyClass = ArrayHelper::remove($options, 'emptyClass', null);
unset($options['header']); unset($options['header']);
$lines = self::collectErrors($models, $encode, $showAllErrors); $lines = self::collectErrors($models, $encode, $showAllErrors);
if (empty($lines)) { if (empty($lines)) {
// still render the placeholder for client-side validation use // still render the placeholder for client-side validation use
$content = '<ul></ul>'; $content = '<ul></ul>';
$options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none'; if ($emptyClass !== null) {
$options['class'] = $emptyClass;
} else {
$options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none';
}
} else { } else {
$content = '<ul><li>' . implode("</li>\n<li>", $lines) . '</li></ul>'; $content = '<ul><li>' . implode("</li>\n<li>", $lines) . '</li></ul>';
} }

View File

@ -1672,6 +1672,11 @@ EOD;
$model->addError('name', 'Error message. Here are even more chars: ""'); $model->addError('name', 'Error message. Here are even more chars: ""');
}, },
], ],
[
'empty_class',
['emptyClass' => 'd-none'],
'<div class="d-none"><p>Please fix the following errors:</p><ul></ul></div>',
],
]; ];
} }