Commit e2743fdb authored by catch's avatar catch
Browse files

Issue #1575060 by andypost, mcjim, nod_: Fixed ajax_html_ids() are broken for...

Issue #1575060 by andypost, mcjim, nod_: Fixed ajax_html_ids() are broken for forms with file element (encoding=multipart/form-data).
parent 2c026bb8
...@@ -3528,7 +3528,8 @@ function drupal_html_id($id) { ...@@ -3528,7 +3528,8 @@ function drupal_html_id($id) {
// requested id. $_POST['ajax_html_ids'] contains the ids as they were // requested id. $_POST['ajax_html_ids'] contains the ids as they were
// returned by this function, potentially with the appended counter, so // returned by this function, potentially with the appended counter, so
// we parse that to reconstruct the $seen_ids array. // we parse that to reconstruct the $seen_ids array.
foreach ($_POST['ajax_html_ids'] as $seen_id) { $ajax_html_ids = explode(' ', $_POST['ajax_html_ids']);
foreach ($ajax_html_ids as $seen_id) {
// We rely on '--' being used solely for separating a base id from the // We rely on '--' being used solely for separating a base id from the
// counter, which this function ensures when returning an id. // counter, which this function ensures when returning an id.
$parts = explode('--', $seen_id, 2); $parts = explode('--', $seen_id, 2);
......
...@@ -284,10 +284,13 @@ Drupal.ajax.prototype.beforeSerialize = function (element, options) { ...@@ -284,10 +284,13 @@ Drupal.ajax.prototype.beforeSerialize = function (element, options) {
// Prevent duplicate HTML ids in the returned markup. // Prevent duplicate HTML ids in the returned markup.
// @see drupal_html_id() // @see drupal_html_id()
options.data['ajax_html_ids[]'] = []; var ids = document.querySelectorAll('[id]');
$('[id]').each(function () { var ajaxHtmlIds = [];
options.data['ajax_html_ids[]'].push(this.id); for (var i = 0, il = ids.length; i < il; i++) {
}); ajaxHtmlIds.push(ids[i].id);
}
// Join IDs to minimize request size.
options.data.ajax_html_ids = ajaxHtmlIds.join(' ');
// Allow Drupal to return new JavaScript and CSS files to load without // Allow Drupal to return new JavaScript and CSS files to load without
// returning the ones already loaded. // returning the ones already loaded.
......
...@@ -1284,9 +1284,12 @@ protected function drupalPostAJAX($path, $edit, $triggering_element, $ajax_path ...@@ -1284,9 +1284,12 @@ protected function drupalPostAJAX($path, $edit, $triggering_element, $ajax_path
$extra_post .= '&' . urlencode($key) . '=' . urlencode($value); $extra_post .= '&' . urlencode($key) . '=' . urlencode($value);
} }
} }
$ajax_html_ids = array();
foreach ($this->xpath('//*[@id]') as $element) { foreach ($this->xpath('//*[@id]') as $element) {
$id = (string) $element['id']; $ajax_html_ids[] = (string) $element['id'];
$extra_post .= '&' . urlencode('ajax_html_ids[]') . '=' . urlencode($id); }
if (!empty($ajax_html_ids)) {
$extra_post .= '&' . urlencode('ajax_html_ids') . '=' . urlencode(implode(' ', $ajax_html_ids));
} }
if (isset($drupal_settings['ajaxPageState'])) { if (isset($drupal_settings['ajaxPageState'])) {
$extra_post .= '&' . urlencode('ajax_page_state[theme]') . '=' . urlencode($drupal_settings['ajaxPageState']['theme']); $extra_post .= '&' . urlencode('ajax_page_state[theme]') . '=' . urlencode($drupal_settings['ajaxPageState']['theme']);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment