When processing form elements that should use Ajax for submitting, Drupal uses "#" selector to process them. Ideally an element ID should be unique, which means this selector should work fine. But that is not always the case, especially when the ajax form was itself loaded using ajax, like #1881486: Not Compatible with AJAX forms inside Views. In fact, ajax.js logic itself is assuming more than one element with the same ID will be returned, hence the each loop in $(element_settings.selector).once('drupal-ajax').each(function () {

The issue is that "#" selector will only return the first matching element and will ignore duplicated IDs. This fix proposes using ID attribute selector instead which returns all elements with that ID.

Comments

shadysamir created an issue. See original summary.

nod_’s picture

Issue tags: +JavaScript

It's clever but that's not the way to go. Duplicate IDs are invalid HTML we can't support this.

In D8 all form element have a new data-drupal-selector attribute that contains the non-randomized element id. that should be used in place of the id. There is also the fact that our Ajax framework is less than great on the frontend side.

shadysamir’s picture

Seems like it would be easy to patch this for 8 and use data-drupal-selector instead of id, which leaves drupal 7 in the dust

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nod_’s picture

Status: Needs review » Needs work

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

aj2r’s picture

Version: 8.3.x-dev » 8.4.x-dev
Status: Needs work » Needs review
Issue tags: +DevDaysSeville
FileSize
580 bytes
569 bytes

Changed id selector to data-drupal-selector.

Status: Needs review » Needs work

The last submitted patch, 8: 2613692-8.patch, failed testing.

droplet’s picture

Potential XSS attack. Needs to trace down where the setting come from.

$(user_passing) still not 100% safe in current jQuery 2.x versions AFAIK.