public function EntityAutocomplete::validateForm in Examples for Developers 8
Same name and namespace in other branches
- 3.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.
Overrides FormInterface::validateForm
File
- ajax_example/
src/ Form/ EntityAutocomplete.php, line 105
Class
- EntityAutocomplete
- A simple autocomplete form which looks up usernames.
Namespace
Drupal\ajax_example\FormCode
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.');
}
}