Form wrapper focus in webformScrollTop not working correctly

Created on 4 June 2024, 6 months ago
Updated 30 July 2024, 4 months ago

Problem/Motivation

In Drupal.AjaxCommands.prototype.webformScrollTop we look for a form element with this code:
var $form = $(response.selector + '-content').find('form');

But it turns out the form never exists inside that wrapper, because the wrapper is opened and closed in the #prefix, rather than opened in the #prefix and closed in the #suffix:

$form += ['#prefix' => '', '#suffix' => ''];
$form['#prefix'] .= '<span id="' . $wrapper_id . '-content"></span>';
$form['#prefix'] .= '<div' . $wrapper_attributes . '>';
$form['#suffix'] = '</div>' . $form['#suffix'];

This means that $form.hasClass('js-webform-autofocus') will always return false because $form is an empty jquery object.

Steps to reproduce

Proposed resolution

Close the wrapping span in the suffix:

$form += ['#prefix' => '', '#suffix' => ''];
$form['#prefix'] .= '<span id="' . $wrapper_id . '-content">';
$form['#prefix'] .= '<div' . $wrapper_attributes . '>';
$form['#suffix'] = '</div></span>' . $form['#suffix'];

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Needs review

Version

6.3

Component

Code

Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024