Add ['#ajax']['refocus'] property to FormAPI elements

Created on 14 February 2019, almost 6 years ago
Updated 11 January 2024, 10 months ago

Links are about to get a 'data-ajax-focus' attribute to allow specifying which element should receive focus after the AJAX command has taken place, in Allow AJAX links to replace a specific selector Needs work .

The very same should be implemented for FormAPI elements, where #ajax currently only allows specifying the (undocumented) 'disable-refocus' property, meaning the focus may only:

  • either go back to the triggering element (default)
  • or remain where it is

Going back to the triggering element is in many cases not desirable, and coupled with the 'blur' event completely it locks the cursor to the triggering element, see 🐛 Focus state bug on text field AJAX calls Fixed . Proceeding without any refocus is not always optimal either, as the element might have been removed or set invisible etc. So what we need is a more flexible way to specify either a specific element or the triggering element ('back' or 'trigger') or 'none' for not refocussing at all.

It's for the 'none' option that I'm proposing $element['#ajax']['refocus'] rather than $element['#ajax']['focus']. Finally there's always a focus, it might just be that we don't want to refocus. Other proposals are welcome, though.

Implementing this would not only help upholding feature parity and consistency, but would also improve our #ajax framework, further reducing the need for "proprietary" JS.

The current $element['#ajax']['disable-refocus'] property should accordingly be deprecated. However many thanks to @DuaelFr for adding it in the first place. Without this, FormAPI's #ajax would in quite a number of cases be dysfunctional.

Feature request
Status

Active

Version

11.0 🔥

Component
Ajax 

Last updated about 9 hours ago

Created by

Pancho UTC+2 🇪🇺 EU

Live updates comments and jobs are added and updated live.
  • API addition

    Enhances an existing API or introduces a new subsystem. Depending on the size and impact, possibly backportable to earlier major versions.

  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

  • Needs issue summary update

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

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