Skip to content

fix: changed modifier permanently suppressed requests on form elements - #4035

Merged
1cg merged 3 commits into
bigskysoftware:four-devfrom
MichaelWest22:fix/changed-modifier-form
Sep 17, 2026
Merged

1cg merged 3 commits into
bigskysoftware:four-devfrom
MichaelWest22:fix/changed-modifier-form

Conversation

@MichaelWest22

@MichaelWest22 MichaelWest22 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Description

Fix changed modifier on forms (closes #4033)

What was broken

hx-trigger="keydown changed" on a <form> silently suppresses every request. Doesn't matter what you type — nothing fires. Works fine on a bare <input>, so it's easy to miss until you try the natural pattern of triggering on the form itself.

Why

The changed block checked .value on the element carrying hx-trigger. For a form that's form.value, which is always undefined:

for (let fromElt of fromElts) {
    if (values.get(fromElt) !== fromElt.value) {  // undefined !== undefined — always false
        changed = true;
    }
}
if (!changed) return;  // always hits this

The fix

Track evt.target instead — the actual input the user typed in. That's always correct regardless of whether the listener is on the input directly, a parent form, or a from: element. Seed on first sight so we don't fire before anything has actually changed.

if (spec.changed) {
    let values = spec.values ??= new WeakMap();
    let target = evt.target;
    let value = target?.value;
    if (!values.has(target)) { values.set(target, value); return; }
    if (values.get(target) === value) return;
    values.set(target, value);
}

Three tests added: direct input suppression, the form bubbling case from #4033, and two inputs in one form tracked independently.

Corresponding issue:
#4033

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@MichaelWest22 MichaelWest22 added bug Something isn't working htmx 4 Issues specific to htmx version 4 labels Sep 7, 2026
@1cg

1cg commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

i think changed doesn't work w/ checkboxes & radio buttons as well. Just stumbled on that looking at:

#2896

@MichaelWest22

Copy link
Copy Markdown
Collaborator Author

Fixed checkboxes and changed support now. best to just ignore and skip them as changed makes no useful sense for them

@1cg
1cg merged commit 2bb525a into bigskysoftware:four-dev Sep 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working htmx 4 Issues specific to htmx version 4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants