bigskysoftware / bigskysoftware/htmx

hx-get="" hx-vals="{index: 2}" creates a duplicate entry instead of replacing index

Open
#3,324 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

Using htmx 2.0.4.

According to https://htmx.org/attributes/hx-vals/ "Input values with the same name will be overridden by variable declarations."

However when I specify an entry with hx-vals, it duplicates the existing entry, which breaks my backend. This is in an SVG element (rust / maud syntax):
```rust
svg {
g {
line
x1=0 y1=0 x2=100 y2=100
hx-get="" // send to current route
hx-vals=(format!(r#"{{"index":{}}}"#, i + 1)) // update index param
hx-swap="innerHTML"
hx-target=(".target")
hx-push-url="true" { }
}
}
```

- The first request goes to the expected route: `/foo?file=...`
- The second requests adds the index param as expected: `/foo?file=...&index=1`
- The third+ requests fail because they look like this: `/foo?file=...&index=1&index=2`

I tried to use `hx-params="* -index"` which indeed removed index from the request URL. However, this seemed to override `hx-vals` and the expected index was never added to the request URL.

Is this a bug in the hx-vals implementation, or am I misunderstanding the docs? "Input values with the same name will be overridden by variable declarations."

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.