Moving the 'actions' form element of a signup form into a wrapper element breaks ajax functionality

Created on 9 November 2023, about 1 year ago

Problem/Motivation + steps to reproduce

In my signup form, I've moved the `$form['actions']` element to a wrapper so the structure is now: `$form['container']['actions']`.
This breaks the ajax submit functionality, because in the ajax submit, the following happens:

public function ajaxSubmit(array $form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $response_wrapper_id = '#' . $form['actions']['submit']['#ajax']['response_wrapper'];
...
}

Proposed resolution

Due to it being bad practice to call the element directly in any case, I propose we replace it with this instead:

public function ajaxSubmit(array $form, FormStateInterface $form_state) {
  $triggering_element = $form_state->getTriggeringElement();
  $response = new AjaxResponse();
  $response_wrapper_id = '#' . $triggering_element['#ajax']['response_wrapper'];
...
}

Then it doesn't matter where the actions element is located, since the button should always be the triggering element.

Remaining tasks

Test MR.

🐛 Bug report
Status

Needs review

Version

2.0

Component

Signup Module

Created by

🇧🇪Belgium RandalV

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024