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
Comments
Comment #3
maithri shetty commentedComment #5
maithri shetty commented@mstrelan I have raised a PR for requested change. Can you please provide me the steps to reproduce the issue so that I can cross verify in my local as well. Thank you.
Comment #6
mstrelan commentedComment #7
maithri shetty commentedComment #8
maithri shetty commented@mstrelan cross verified and works fine. Thank you
Comment #9
mh_nichtsHello,
Thanks for filing this issue.
However, I suggest solving it in another way, as using a span to wrap a div and a whole form is invalid according to W3C HTML standards.
My suggestion would be :
I will try to commit these changes next week.
Comment #11
liam morlandPlease rebase against 6.3.x.
Comment #12
mh_nichts@lkmorlan Thank you ! It should be OK now, I could apply the patch from the MR locally.
Comment #13
mh_nichtsComment #15
jrockowitz commentedWe can't have a DIV wrapper with a SPAN but we can convert the SPAN to a DIV and then wrap the form,
Comment #16
mh_nichts@jrockowitz Thanks for the changes.
It seems OK for me regarding the structure, but it still misses tabindex="-1" to effectively get the focus (as a div is not focusable by default).
Comment #17
jrockowitz commentedDone!
Comment #18
jrockowitz commentedComment #20
liam morland