diff --git a/core/assets/scaffold/files/default.settings.php b/core/assets/scaffold/files/default.settings.php index 286586288bdf47c7c1041a97b1cabfe42c30dcb2..52b18e1e882d7953496e3e940f533dfcdcb87993 100644 --- a/core/assets/scaffold/files/default.settings.php +++ b/core/assets/scaffold/files/default.settings.php @@ -707,6 +707,22 @@ # $config['system.site']['name'] = 'My Drupal site'; # $config['user.settings']['anonymous'] = 'Visitor'; +/** + * Enable HTML5 form validation. + * + * Drupal disables HTML5 form validation by default due to issues with + * usability and accessibility. Setting this to TRUE will allow user agents to + * perform client-side HTML5 validation. This prevents Drupal's Form API (FAPI) + * validation from executing, so FAPI validation error messages may not be + * displayed including those for required elements. + * + * This setting will be removed in Drupal 13. HTML form validation will always + * be disabled. + * + * @see https://www.drupal.org/node/3537128 + */ +# $settings['enable_html5_validation'] = TRUE; + /** * Load services definition file. */ diff --git a/core/lib/Drupal/Core/Form/FormPreprocess.php b/core/lib/Drupal/Core/Form/FormPreprocess.php index 3b3bad33ef4eac0615d43f7ebd7afdc3780852ba..342f92f1ff264895a3186652ce34ff0fd9a2bcc1 100644 --- a/core/lib/Drupal/Core/Form/FormPreprocess.php +++ b/core/lib/Drupal/Core/Form/FormPreprocess.php @@ -5,6 +5,7 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Render\Element; use Drupal\Core\Render\Element\RenderElementBase; +use Drupal\Core\Site\Settings; use Drupal\Core\Template\Attribute; /** @@ -33,6 +34,11 @@ public function preprocessForm(array &$variables): void { if (empty($element['#attributes']['accept-charset'])) { $element['#attributes']['accept-charset'] = "UTF-8"; } + if (!Settings::get('enable_html5_validation', FALSE)) { + // Prevent client-side HTML5 validation for usability and accessibility. + // @see https://www.drupal.org/node/3537128 + $element['#attributes']['novalidate'] = TRUE; + } $variables['attributes'] = $element['#attributes']; $variables['children'] = $element['#children']; } diff --git a/core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php b/core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php index df00763b565b787f548d35cd19037decb087a52a..224156b135e797fe6d8011400e9a261d6c999f6f 100644 --- a/core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php +++ b/core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php @@ -71,7 +71,7 @@ public function testRenderLayout($layout_id, $config, $regions, array $html): vo // Add in the wrapping form elements and prefix/suffix. array_unshift($html, 'Test prefix'); - array_unshift($html, '