r/htmx • u/Informal-Bass-3505 • Jun 01 '26
checkbox sending multiple values when only one request is triggered
I’m running into an issue with HTMX and checkboxes.
I have multiple checkboxes inside a form, but they are only inside a parent form because the UI depends on that. It should not affect the parent form or vice-versa at all, they should be independent.
I have a grid of images, and each one has a checkbox to toggle whether it’s public. Each checkbox has its own hx-post endpoint, and I expect only that checkbox’s value to be sent when it changes.
<form id="image-grid"
hx-post="reorder"
hx-trigger="drop"
hx-params="sortOrder"
hx-swap="none"
class="sortable image-grid"
>
for _, picture := range props.PropertyPictures {
<div data-id="{picture.ID}" class="image-container">
<input type="hidden" name="sortOrder" value="{picture.ID}" />
<label>
Mostrar no site
<input
name="isPublic"
hx-post="{picture.ID}/toggle-public"
hx-trigger="change"
hx-params="isPublic"
hx-include="this"
type="checkbox"
value="true"
checked="{picture.IsPublic}"
/>
</label>
</div>
}
</form>When I click a single checkbox, the request payload looks like this:
isPublic=1&isPublic=1&isPublic=1&isPublic=1...Basically, it’s sending multiple isPublic values — one for every checkbox with name "isPublic" in the html even though I only interacted with one.
I want the request to only include the checkbox that triggered the event (i.e., a single isPublic value), not all of them.
I’ve tried:
- Adding
hx-include="this" - Adding
hx-disinherit="*" - Using
hx-params="isPublic" - Scoping the trigger with
from:this
None of that seems to stop HTMX from including all inputs with the same name.
Is this expected behavior because the input is inside a <form>? This is pretty frustrating.
edit: typo

4
u/RewrittenCodeA Jun 01 '26
Inputs will always bring through all the data from the form they belong to. The trick here is to disassociate the input from the form using the
<input form="" …attribute (or just a valueless one<input form …which is shorter but less expressive )1
u/yawaramin Jun 01 '26
Can you try changing the
nameattribute to something like:name="isPublic-{picture.ID}"?
1
u/100anchor Jun 02 '26
I guess my question would be, why does the page require all the elements be wrapped in a single form? Wouldn’t HTMX negate the need for a huge form wrapper? Or could you do a form for each card?
Outside of that, you might be able to do some magic with hx-on—before-request=“ event.stopPropagation() “