3 namespace Drupal\ajax_forms_test;
5 use Drupal\Core\Ajax\AjaxResponse;
6 use Drupal\Core\Ajax\DataCommand;
7 use Drupal\Core\Ajax\HtmlCommand;
8 use Drupal\Core\Form\FormStateInterface;
11 * Simple object for testing methods as Ajax callbacks.
16 * Ajax callback triggered by select.
18 public function selectCallback($form, FormStateInterface $form_state) {
19 $response = new AjaxResponse();
20 $response->addCommand(new HtmlCommand('#ajax_selected_color', $form_state->getValue('select')));
21 $response->addCommand(new DataCommand('#ajax_selected_color', 'form_state_value_select', $form_state->getValue('select')));
26 * Ajax callback triggered by checkbox.
28 public function checkboxCallback($form, FormStateInterface $form_state) {
29 $response = new AjaxResponse();
30 $response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state->getValue('checkbox')));
31 $response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state->getValue('checkbox')));
36 * Ajax callback triggered by the checkbox in a #group.
38 public function checkboxGroupCallback($form, FormStateInterface $form_state) {
39 return $form['checkbox_in_group_wrapper'];