2

Anything I could find related to this question was for Drupal 7.

I am building a form that needs to perform a certain ajax function when a date is selected. I have built my form to work similarly to the "Form API Examples - Ajax Form Example" part of the Examples module.

To test, I set it up so that, like in the example, when this Select element is changed it triggers the function "dateCallback":

$form['dropdown'] = [
    '#title' => $this->t('Test'),
    '#type' => 'select',
    '#options' => ['option1' => '1', 'option2' => '2'],
    '#ajax' => [
        'callback' => '::dateCallback',
        'wrapper' => 'log-wrapper',
    ],
];

This executes perfectly.

However, when I try to set up a Date element to do the same function, nothing happens. No Ajax spinner, just nothing happens at all.

$form['date'] = array(
    '#type' => 'date',
    '#title' => t('Date'),
    '#ajax' => [
        'callback' => '::dateCallback',
        'wrapper' => 'log-wrapper',
    ],
);

It does not work even if I include 'event' => 'onchange' in the #ajax array.

Is it possible to make ajax functions trigger on a changed date field?

1 Answer 1

1

After some more searching I found a patch for this issue here: https://www.drupal.org/node/2781103

Seems to be working for me in Drupal 8.2.6. I did have to restart apache before it started to work, maybe a cache clear was all I needed for it though.

Not sure if I should accept this answer since it may become quickly outdated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.