public static function Table::validateTable

public static Table::validateTable(&$element, FormStateInterface $form_state, &$complete_form)

#element_validate callback for #type 'table'.

Parameters

array $element: An associative array containing the properties and children of the table element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

File

core/lib/Drupal/Core/Render/Element/Table.php, line 251

Class

Table
Provides a render element for a table.

Namespace

Drupal\Core\Render\Element

Code

public static function validateTable(&$element, FormStateInterface $form_state, &$complete_form) {
  // Skip this validation if the button to submit the form does not require
  // selected table row data.
  $triggering_element = $form_state->getTriggeringElement();
  if (empty($triggering_element['#tableselect'])) {
    return;
  }
  if ($element['#multiple']) {
    if (!is_array($element['#value']) || !count(array_filter($element['#value']))) {
      $form_state->setError($element, t('No items selected.'));
    }
  }
  elseif (!isset($element['#value']) || $element['#value'] === '') {
    $form_state->setError($element, t('No item selected.'));
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Table.php/function/Table::validateTable/8.1.x