Replace #ajax['wrapper'] with #ajax['wrapper_selector']

Created on 24 October 2016, about 8 years ago
Updated 5 April 2023, over 1 year ago

Problem/Motivation

Currently it is not possible to target HTML classes to replace with AJAX, an ID must be used.

This sucks because the Form API goes to great lengths to make HTML IDs unique, which is why data-drupal-selector was introduced back in 2015 when dinosaurs roamed the Earth (see https://www.drupal.org/node/2503277 ). Therefore, any element which you want to target with AJAX usually needs to be forcibly wrapped with markup to ensure an unchanging ID:

$element['#prefix'] = '<div id="ajax-target">';
$element['#suffix'] = '</div>';

Ugh. Besides being smelly code, the code which forcibly adds '#' to the wrapper string actually has a @todo to improve this situation. Let's do what it says, and make the AJAX targeting a little bit more flexible.

Proposed resolution

Leave #ajax['wrapper'] for BC, but introduce #ajax['selector'] instead.
Before:

'wrapper' => 'some-string',

After:

'wrapper_selector' => '#some-string',

Remaining tasks

N/A

User interface changes

N/A

API changes

#ajax['wrapper'] is deprecated, but has BC.

Data model changes

N/A

📌 Task
Status

Needs work

Version

10.1

Component
Ajax 

Last updated 2 days ago

Created by

🇺🇸United States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024