Loading indicators for non-AJAX form buttons

AJAX forms in Drupal show a progress indicator while they work. This module does the same for ordinary form submissions: the button shows that the form is submitting, and a second submit is blocked until the page loads.

Three indicator types:

  1. A spinner on the button
  2. Drupal's AJAX throbber next to the button
  3. Drupal's AJAX fullscreen progress indicator

Configuration

  1. Install and enable the module
  2. Visit Admin / Config / User Interface / Submit Indicator
  3. Choose your default indicator type (spinner, throbber, or fullscreen)
  4. Done - every non-AJAX form now shows feedback on submit

You can also set the indicator per form or per button.

For every setting and theming option, see the README.md.

Features

  • Three indicator types: a spinner on the button, Drupal's throbber next to the button, or Drupal's fullscreen progress indicator
  • Automatic or opt-in: every form by default, or only the forms you list
  • Form API property: #submit_indicator sets the indicator per form and per button (similar to #ajax)
  • Exclusions: AJAX forms are skipped automatically; admin pages, form IDs (with wildcards), and anything with the exclusion class can be left out
  • Theme-friendly: the "disabled" look uses the theme's own disabled button style (Drupal's is-disabled class), with a gray default; spinner color and image are set with CSS custom properties
  • Accessible: buttons are marked aria-disabled without leaving the submitted data, and the spinner slows down for users who prefer reduced motion
  • Client-side validation: the indicator resets when the browser's validation or Clientside Validation stops the submit

How it works

When a user submits a non-AJAX form:

  1. The configured indicator (spinner, throbber, or fullscreen) is shown
  2. A second submit, from any button or the Enter key, is blocked
  3. The form's submit buttons are optionally marked as disabled
  4. If client-side validation fails, the indicator resets immediately
  5. If the form submits, the page loads and the indicator is gone, also when the user comes back with the browser's Back button
  6. A configurable timeout resets the indicator if the page doesn't load

A script that cancels the submit to do its own work first, such as getting a payment token, resets the indicator on an error by dispatching one event:

form.dispatchEvent(new CustomEvent('submit-indicator-reset'));

Usage: #submit_indicator property

// Use the fullscreen indicator for a form
$form['#submit_indicator'] = ['type' => 'fullscreen'];

// Shorthand - just pass the type
$form['#submit_indicator'] = 'throbber';

// Disable for a specific button
$form['actions']['preview']['#submit_indicator'] = FALSE;

// Disable for the entire form
$form['#submit_indicator'] = FALSE;

// Spinner with custom color
$form['actions']['submit']['#submit_indicator'] = [
  'type' => 'spinner',
  'color' => '#000000',
];

Available options

  • type - 'spinner', 'throbber', or 'fullscreen'
  • color - Spinner color; empty uses the button's text color (spinner only)
  • position - 'end', 'start', or 'center' (spinner only)
  • room - Widen the button's padding for the spinner (spinner only)
  • text - Text on the button while the form submits
  • look - 'button' or 'disabled'
  • message - Text shown next to the throbber (throbber only)
  • disableButton - Mark the submit buttons as disabled while the form submits (default: true)

Similar modules

Requirements

  • Drupal 10.1 or later, 11, or 12

Project information

Releases