diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index 46c6f297e3..4b71b7b915 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -138,7 +138,6 @@ public static function setAttributes(&$element, $class = []) { // \Drupal::formBuilder()->doBuildForm(). if (!empty($element['#required'])) { $element['#attributes']['class'][] = 'required'; - $element['#attributes']['required'] = 'required'; $element['#attributes']['aria-required'] = 'true'; } if (isset($element['#parents']) && isset($element['#errors']) && !empty($element['#validated'])) { diff --git a/core/misc/states.js b/core/misc/states.js index 2b9d3b886a..172a601c29 100644 --- a/core/misc/states.js +++ b/core/misc/states.js @@ -321,13 +321,13 @@ if (e.trigger) { if (e.value) { var label = 'label' + (e.target.id ? '[for=' + e.target.id + ']' : ''); - var $label = $(e.target).attr({ required: 'required', 'aria-required': 'aria-required' }).closest('.js-form-item, .js-form-wrapper').find(label); + var $label = $(e.target).attr({'aria-required': 'aria-required'}).closest('.js-form-item, .js-form-wrapper').find(label); if (!$label.hasClass('js-form-required').length) { $label.addClass('js-form-required form-required'); } } else { - $(e.target).removeAttr('required aria-required').closest('.js-form-item, .js-form-wrapper').find('label.js-form-required').removeClass('js-form-required form-required'); + $(e.target).removeAttr('aria-required').closest('.js-form-item, .js-form-wrapper').find('label.js-form-required').removeClass('js-form-required form-required'); } } }); @@ -373,4 +373,4 @@ return typeof a === 'undefined' || typeof b === 'undefined'; } -})(jQuery, Drupal); \ No newline at end of file +})(jQuery, Drupal); diff --git a/core/modules/filter/tests/src/Functional/FilterFormTest.php b/core/modules/filter/tests/src/Functional/FilterFormTest.php index fb0046b08a..a9091ffbce 100644 --- a/core/modules/filter/tests/src/Functional/FilterFormTest.php +++ b/core/modules/filter/tests/src/Functional/FilterFormTest.php @@ -244,7 +244,7 @@ protected function assertOptions($id, array $expected_options, $selected) { * TRUE if the assertion passed; FALSE otherwise. */ protected function assertRequiredSelectAndOptions($id, array $options) { - $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', [ + $select = $this->xpath('//select[@id=:id and contains(@class, "required")]', [ ':id' => $id, ]); $this->assertNotEmpty($select, SafeMarkup::format('Required field @id exists.', [ diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml index 9e178cd51a..1352b09c28 100644 --- a/core/modules/system/tests/modules/form_test/form_test.routing.yml +++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml @@ -402,9 +402,9 @@ form_test.checkboxes_zero: _access: 'TRUE' form_test.required: - path: '/form-test/required-attribute' + path: '/form-test/required-fields' defaults: - _form: '\Drupal\form_test\Form\FormTestRequiredAttributeForm' + _form: '\Drupal\form_test\Form\FormTestRequiredFieldsForm' _title: 'Required' requirements: _access: 'TRUE' diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredAttributeForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredFieldsForm.php similarity index 83% rename from core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredAttributeForm.php rename to core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredFieldsForm.php index 6c6ff3a4fa..70e2a63a57 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredAttributeForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestRequiredFieldsForm.php @@ -6,17 +6,17 @@ use Drupal\Core\Form\FormStateInterface; /** - * Builds a form to test the required attribute. + * Builds a form to test required fields. * * @internal */ -class FormTestRequiredAttributeForm extends FormBase { +class FormTestRequiredFieldsForm extends FormBase { /** * {@inheritdoc} */ public function getFormId() { - return 'form_test_required_attribute'; + return 'form_test_required_fields'; } /** diff --git a/core/modules/system/tests/src/Functional/Form/FormTest.php b/core/modules/system/tests/src/Functional/Form/FormTest.php index 87c7632457..2c1701989c 100644 --- a/core/modules/system/tests/src/Functional/Form/FormTest.php +++ b/core/modules/system/tests/src/Functional/Form/FormTest.php @@ -747,27 +747,4 @@ public function testInputForgery() { $this->assertText('An illegal choice has been detected.', 'Input forgery was detected.'); } - /** - * Tests required attribute. - */ - public function testRequiredAttribute() { - $this->drupalGet('form-test/required-attribute'); - $expected = 'required'; - // Test to make sure the elements have the proper required attribute. - foreach (['textfield', 'password'] as $type) { - $element = $this->xpath('//input[@id=:id and @required=:expected]', [ - ':id' => 'edit-' . $type, - ':expected' => $expected, - ]); - $this->assertTrue(!empty($element), format_string('The @type has the proper required attribute.', ['@type' => $type])); - } - - // Test to make sure textarea has the proper required attribute. - $element = $this->xpath('//textarea[@id=:id and @required=:expected]', [ - ':id' => 'edit-textarea', - ':expected' => $expected, - ]); - $this->assertTrue(!empty($element), 'The textarea has the proper required attribute.'); - } - }