How do I add an ajax item on the submit button? I created a form using the module "Webform". Now I want to add an #ajax item to the submit button.

Here's what I already did:

use \Drupal\Core\Form\FormStateInterface;

function mytheme_form_alter(&amp;$form, FormStateInterface $form_state, $form_id)
{
  $form['#submit']['#ajax'] = array(
    'callback' =&gt; '\Drupal\mymodule\Controller\DefaultController::process_form_submission'
  );
}


The '#submit' field of the form now looks like this:

'#submit' =&gt; array(2)
    '0' =&gt; string(12) "::submitForm"
    '#ajax' =&gt; array(1)
        'callback' =&gt; string(72) "\Drupal\mymodule\Controller\DefaultController::process_form_submission"


But the process_form_submission function is not called. Instead the page reloads on submit as before.
Try this:

$form['actions']['submit']['#ajax'] = array(
        'callback' =&gt; '\Drupal\mymodule\Controller\DefaultController::process_form_submission',
'event' =&gt; 'click',
      );