diff --git a/core/includes/form.inc b/core/includes/form.inc index 49ace44..5ce9ae6 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -4614,7 +4614,7 @@ function _form_set_class(&$element, $class = array()) { $element['#attributes']['required'] = 'required'; $element['#attributes']['aria-required'] = 'true'; } - if (isset($element['#parents']) && form_get_error($element) !== NULL) { + if (isset($element['#parents']) && form_get_error($element) && !empty($element['#validated'])) { $element['#attributes']['class'][] = 'error'; } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php index 92898e0..9ded61f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php @@ -247,7 +247,7 @@ function testRequiredTextfieldNoTitle() { $this->assertNoRaw("The form_test_validate_required_form_no_title form was submitted successfully.", 'Validation form submitted successfully.'); // Check the page for the error class on the textfield. - $this->assertFieldByXPath('//input[contains(@class, "error")]', FALSE, 'Error input form element class found.'); + $this->assertNoFieldByXpath('//input[contains(@class, "error")]', FALSE, 'Error input form element class found.'); // Submit again with required fields set and verify that there are no // error messages.