drupal-form-ajax

Implement Drupal 11 AJAX form callbacks and dynamic rebuilds with Form API commands.

67|13|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/edutrul/drupal-ai --skill drupal-form-ajax
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drupal-form-ajax
Source: https://github.com/edutrul/drupal-ai/tree/main/.claude/skills/drupal-form-ajax
Command: npx skills add https://github.com/edutrul/drupal-ai --skill drupal-form-ajax

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Drupal AJAX forms can be verbose and error-prone. This skill consolidates common patterns for AJAX callbacks, AjaxResponse commands, and dynamic form rebuilding into a clear, reusable guide.

Core Features & Use Cases

  • Unified AJAX pattern: Centralizes the callback structure, wrapper handling, and build/rebuild flow for Drupal 11 forms.
  • Command examples: Demonstrates usage of ReplaceCommand, HtmlCommand, InvokeCommand, and MessageCommand to update the UI without a full page reload.
  • Real-world scenarios: Supports dynamic field updates, conditional element visibility, and multi-step forms triggered by user actions.

Quick Start

Implement the provided Drupal AJAX form pattern in your module's Form class and adapt it to your form elements.

Frequently Asked Questions about drupal-form-ajax

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Drupal Form API #ajax to update select options dynamically?

To update select options dynamically using Drupal Form API #ajax, you define an AJAX callback that returns an AjaxResponse with ReplaceCommand or HtmlCommand to swap the wrapper element without a full page reload. This pattern streamlines dynamic form rebuilds by centralizing callback structures and wrapper handling for Drupal 11 modules.

What is the best way to rebuild a Drupal 11 form section after an AJAX user action?

The best way to rebuild a Drupal 11 form section after an AJAX user action is using the setRebuild pattern within your Form class. This approach triggers a dynamic form rebuild, allowing conditional element visibility and multi-step form progression while preserving existing user input through centralized AJAX callback management.

When should I use ReplaceCommand versus HtmlCommand in an AjaxResponse callback?

Use ReplaceCommand in an AjaxResponse callback to swap an entire form element with new HTML, whereas HtmlCommand targets a specific wrapper to inject content. Both update the UI without a full page reload, but ReplaceCommand handles full element replacement while HtmlCommand manages inner content updates.

Can I trigger conditional element visibility in Drupal forms using InvokeCommand?

Yes, you can trigger conditional element visibility in Drupal forms using InvokeCommand within an AjaxResponse. InvokeCommand executes custom jQuery commands on specified selectors, allowing you to dynamically show or hide form elements based on user actions without requiring a full page reload.

Does this Drupal AJAX form pattern work for multi-step forms in Drupal 11?

Yes, this Drupal AJAX form pattern works for multi-step forms in Drupal 11. It supports real-world scenarios including dynamic field updates, conditional element visibility, and multi-step forms triggered by user actions, consolidating verbose AJAX callback structures into a reusable guide for module development.

Why does my Drupal AJAX callback not update the form wrapper after a selection change?

If your Drupal AJAX callback does not update the form wrapper after a selection change, the issue likely stems from incorrect wrapper handling or missing setRebuild calls. This skill provides a unified AJAX pattern that centralizes callback structure and build/rebuild flow to prevent these verbose, error-prone mistakes.