function EntityAutocomplete::validateForm

Same name and namespace in other branches
  1. 4.0.x modules/ajax_example/src/Form/EntityAutocomplete.php \Drupal\ajax_example\Form\EntityAutocomplete::validateForm()

Here we validate and signal an error if there are no users selected.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormInterface::validateForm

File

modules/ajax_example/src/Form/EntityAutocomplete.php, line 105

Class

EntityAutocomplete
A simple autocomplete form which looks up usernames.

Namespace

Drupal\ajax_example\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $state_users = $form_state->getValue('users');
  if (empty($state_users)) {
    $form_state->setErrorByName('users', 'There were no users selected.');
  }
}