Commit 278c50e0 authored by catch's avatar catch

Issue #2781103 by Dom., k4v, gaurav.kapoor, mpdonadio, dawehner, Lendude: Date...

Issue #2781103 by Dom., k4v, gaurav.kapoor, mpdonadio, dawehner, Lendude: Date FAPI element type do not allow AJAX via #ajax API
parent 1188f1c1
......@@ -22,6 +22,16 @@ public function selectCallback($form, FormStateInterface $form_state) {
return $response;
}
/**
* Ajax callback triggered by date.
*/
public function dateCallback($form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$response->addCommand(new HtmlCommand('#ajax_date_value', $form_state->getValue('date')));
$response->addCommand(new DataCommand('#ajax_date_value', 'form_state_value_date', $form_state->getValue('date')));
return $response;
}
/**
* Ajax callback triggered by datetime.
*/
......
......@@ -24,6 +24,15 @@ public function getFormId() {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$callback_object = new Callbacks();
$form['date'] = [
'#type' => 'date',
'#ajax' => [
'callback' => [$callback_object, 'dateCallback'],
],
'#suffix' => '<div id="ajax_date_value">No date yet selected</div>',
];
$form['datetime'] = [
'#type' => 'datetime',
'#ajax' => [
......@@ -34,7 +43,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['datetime_result'] = [
'#type' => 'markup',
'#markup' => '<div id="ajax_datetime_value">No date selected.</div>',
'#markup' => '<div id="ajax_datetime_value">No datetime selected.</div>',
];
return $form;
......
......@@ -19,14 +19,28 @@ class AjaxCallbacksTest extends JavascriptTestBase {
/**
* Tests if Ajax callback works on date element.
*/
public function testDateTimeAjaxCallback() {
public function testDateAjaxCallback() {
// Test Ajax callback when date changes.
$this->drupalGet('ajax_forms_test_ajax_element_form');
$this->assertSession()->responseContains('No date selected.');
$this->assertSession()->responseContains('No date yet selected');
$this->getSession()->getPage()->fillField('edit-date', '2016-01-01');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->responseNotContains('No date yet selected');
$this->assertSession()->responseContains('2016-01-01');
}
/**
* Tests if Ajax callback works on datetime element.
*/
public function testDateTimeAjaxCallback() {
// Test Ajax callback when datetime changes.
$this->drupalGet('ajax_forms_test_ajax_element_form');
$this->assertSession()->responseContains('No datetime selected.');
$this->getSession()->getPage()->fillField('edit-datetime-date', '2016-01-01');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->responseNotContains('No date selected.');
$this->assertSession()->responseNotContains('No datetime selected.');
$this->assertSession()->responseContains('2016-01-01');
$this->getSession()->getPage()->fillField('edit-datetime-time', '12:00:00');
$this->assertSession()->assertWaitOnAjaxRequest();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment