You are here

public function Callbacks::dateCallback in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php \Drupal\ajax_forms_test\Callbacks::dateCallback()

Ajax callback triggered by date.

File

core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php, line 28

Class

Callbacks
Simple object for testing methods as Ajax callbacks.

Namespace

Drupal\ajax_forms_test

Code

public function dateCallback($form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $date = $form_state
    ->getValue('date');
  $response
    ->addCommand(new HtmlCommand('#ajax_date_value', sprintf('<div>%s</div>', $date)));
  $response
    ->addCommand(new DataCommand('#ajax_date_value', 'form_state_value_date', $form_state
    ->getValue('date')));
  return $response;
}