summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-10-02 13:18:20 (GMT)
committerNathaniel Catchpole2017-10-02 13:19:58 (GMT)
commit278c50e0dc096fa21739a24949cf979ef3137659 (patch)
treea23cc9cf65275ac96b9546c02c92ab92c508ae25
parent1188f1c144010f5b3e4d0483dc325578bd4f3eca (diff)
Issue #2781103 by Dom., k4v, gaurav.kapoor, mpdonadio, dawehner, Lendude: Date FAPI element type do not allow AJAX via #ajax API
-rw-r--r--core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php10
-rw-r--r--core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php11
-rw-r--r--core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php20
3 files changed, 37 insertions, 4 deletions
diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php b/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php
index 0c91513..9b35ef7 100644
--- a/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php
+++ b/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php
@@ -23,6 +23,16 @@ class Callbacks {
}
/**
+ * 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.
*/
public function datetimeCallback($form, FormStateInterface $form_state) {
diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php
index 3a1e746..0290f81 100644
--- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php
+++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php
@@ -24,6 +24,15 @@ class AjaxFormsTestAjaxElementsForm extends FormBase {
*/
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 @@ class AjaxFormsTestAjaxElementsForm extends FormBase {
$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;
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php
index c45c590..e13ecfd 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php
@@ -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();