Repository navigation
[#26] Added the 'formIdAttributes' setting so Drupal forms send a stable 'form_id' across AJAX redraws. - #29
Merged
Merged
Conversation
|
Warning Review limit reached
This review includes 9 billable files and costs up to $2.25.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 29 minutes for your next included review. View limit details
|
AlexSkrypnyk
force-pushed
the
feature/26-stable-form-id
branch
from
November 16, 2026 09:30
509e8dd to
4564ec7
Compare
…ble 'form_id' across AJAX redraws.
AlexSkrypnyk
force-pushed
the
feature/26-stable-form-id
branch
from
November 16, 2026 09:46
4564ec7 to
8ac22b3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #26
Summary
form_idnow comes from the attributes listed in a newformIdAttributessetting, and the Drupal bundles default it to['data-drupal-selector', 'id']. So a Drupal form keeps the sameform_idonform_startand everyfield_complete, even after an AJAX response redraws it.formParams()insrc/core/dom.jssent the marked element'sidas it was. Drupal'sHtml::getUniqueId()adds a random--<token>suffix to a form'sidevery time it's rebuilt, for example when an AJAX submission comes back with validation errors. So 1 attempt reportedwebform-submission-contact-paragraph-40-add-formand thenwebform-submission-contact-paragraph-40-add-form--sKry3dUurl4, and the 2 values didn't group together in GA4.After this merges, Drupal sites send the
data-drupal-selectorvalue asform_id. Drupal derives that value from the form ID without the suffix, and a marked wrapper without one still sends itsid. Standalone and ESM bundles keep the['id']default, so what they send doesn't change.form_nameand theform_startdeduplication, which keys on the name, aren't touched. Sites can override the list throughdrupalSettings.axel.formIdAttributesorwindow.axelSettings, and a value that isn't an array of strings throws when the instance is created.Before / After
Changes
Core
src/core/core.js: addedformIdAttributes: ['id']toDEFAULT_SETTINGS. The constructor throws when the value isn't an array of strings, the same way it already checkstypesandcollectors.src/core/dom.js:formParams(form, settings)readsform_idfrom the first attribute insettings.formIdAttributesthat has a non-empty value. It still passes the same settings toresolveUrl()forform_destination. Both form event types already passaxel.settings, so their call sites don't change.Drupal integration
src/integrations/drupal.js:attach()setsformIdAttributesto['data-drupal-selector', 'id']underneathdrupalSettings.axel, so a site setting still wins.Tests
tests/core/event-types/form-start.test.js: covers the first listed attribute winning, falling back when the first attribute is missing or empty, and sending noform_idwhen no attribute matches or the list is empty.tests/core/event-types/field-complete.test.js:field_completereads the same attributes.tests/core/core.test.js: the constructor throws on a string and on a list that holds a non-string.tests/integrations/drupal.test.js: checks the Drupal default and thedrupalSettingsoverride, and that a form redrawn with a new--tokenidsends the sameform_idonform_startandfield_complete.Docs
README.md: theform_idbullet explains the Drupal behavior, and the settings table has aformIdAttributesrow.docs/architecture/README.md: the Drupal start paragraph and the form event type bullets cover the new setting.