diff --git a/core/modules/shortcut/src/Form/SwitchShortcutSet.php b/core/modules/shortcut/src/Form/SwitchShortcutSet.php index e7ee0e19986..72f5160e73f 100644 --- a/core/modules/shortcut/src/Form/SwitchShortcutSet.php +++ b/core/modules/shortcut/src/Form/SwitchShortcutSet.php @@ -100,6 +100,9 @@ class SwitchShortcutSet extends FormBase { 'visible' => array( ':input[name="set"]' => array('value' => 'new'), ), + 'required' => array( + ':input[name="set"]' => array('value' => 'new'), + ), ), ); $form['id'] = array( @@ -162,7 +165,7 @@ class SwitchShortcutSet extends FormBase { if ($form_state->getValue('set') == 'new') { // Check to prevent creating a shortcut set with an empty title. if (trim($form_state->getValue('label')) == '') { - $form_state->setErrorByName('new', $this->t('The new set label is required.')); + $form_state->setErrorByName('label', $this->t('The new set label is required.')); } } } diff --git a/core/modules/shortcut/src/Tests/ShortcutSetsTest.php b/core/modules/shortcut/src/Tests/ShortcutSetsTest.php index 417e91890b6..56fce39422c 100644 --- a/core/modules/shortcut/src/Tests/ShortcutSetsTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutSetsTest.php @@ -134,6 +134,7 @@ class ShortcutSetsTest extends ShortcutTestBase { $this->assertText(t('The new set label is required.')); $current_set = shortcut_current_displayed_set($this->adminUser); $this->assertEqual($current_set->id(), $this->set->id(), 'Attempting to switch to a new shortcut set without providing a set name does not succeed.'); + $this->assertFieldByXPath("//input[@name='label' and contains(concat(' ', normalize-space(@class), ' '), ' error ')]", NULL, 'The new set label field has the error class'); } /**