diff -u b/modules/demo/src/Tests/TMGMTDemoTest.php b/modules/demo/src/Tests/TMGMTDemoTest.php --- b/modules/demo/src/Tests/TMGMTDemoTest.php +++ b/modules/demo/src/Tests/TMGMTDemoTest.php @@ -53,6 +53,10 @@ // Check to see if no items are selected and the error message pops up. $this->drupalPostForm('admin/tmgmt/sources', array(), t('Request translation')); $this->assertUniqueText(t("You didn't select any source objects.")); + $this->drupalPostForm('admin/tmgmt/sources', array(), t('Search')); + $this->assertNoText(t("You didn't select any source objects.")); + $this->drupalPostForm('admin/tmgmt/sources', array(), t('Cancel')); + $this->assertNoText(t("You didn't select any source objects.")); } } diff -u b/src/Form/SourceOverviewForm.php b/src/Form/SourceOverviewForm.php --- b/src/Form/SourceOverviewForm.php +++ b/src/Form/SourceOverviewForm.php @@ -155,10 +155,16 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $items = array_filter($form_state->getValue('items')); $is_search = FALSE; - if ($form_state->getValue('op') == t('Search')) { + $is_cancel = FALSE; + if ($form['search_wrapper']['search_submit']['#value'] == $form_state->getTriggeringElement()['#value']) { $is_search = TRUE; } - if (empty($items) && !$is_search) { + if (array_key_exists('search_cancel', $form['search_wrapper'])) { + if ($form['search_wrapper']['search_cancel']['#value'] == $form_state->getTriggeringElement()['#value']) { + $is_cancel = TRUE; + } + } + if (!$items && !$is_search && !$is_cancel) { $form_state->setError($form, t("You didn't select any source objects.")); } $plugin = $form_state->get('plugin');