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.

Issue fork mailchimp-3400501

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

RandalV created an issue. See original summary.

randalv’s picture

MR 's been updated, although I don't see the changes come through yet here in the issue itself.

randalv’s picture

Status: Active » Needs review

xenophyle made their first commit to this issue’s fork.

  • xenophyle committed 4baaec6d on 2.x authored by randalv
    feat: #3400501 Allow moving the submit form element of a signup form...

  • xenophyle committed 36ee7b83 on 3.x authored by randalv
    feat: #3400501 Allow moving the submit form element of a signup form...

  • xenophyle committed 9997c9b6 on 3.2.x authored by randalv
    feat: #3400501 Allow moving the submit form element of a signup form...
xenophyle’s picture

Status: Needs review » Fixed

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.