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 257

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.'));
  }
}
doc_Drupal
2016-10-29 09:46:03
Comments
Leave a Comment

Please login to continue.