-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow hx-include
and hx-vals
to specify an HTTP method explicitly
#3174
Comments
Also... Instead of the <form hx-post="/update" hx-include="#filters" hx-vals="{ key: 'value' } get">
<input type="text" name="name" value="John">
<button type="submit">Submit</button>
</form>
<div id="filters">
<input type="hidden" name="id" value="123" hx-val="post">
<input type="text" name="search" value="abc" hx-val="get">
<select name="category" hx-val="get">
<option value="1" selected>Category 1</option>
<option value="2">Category 2</option>
</select>
</div> |
Hey, while I understand the usecase, I think we would welcome this as a community extension rather than a new feature in the core library. A new extension would perfectly fit here I think, letting you enable that extra behavior if you need it without making the core lib heavier, see our extensions guidelines to get started! |
Thank you for your response. I will look into it.
|
Description:
Currently,
hx-include
andhx-vals
always include data in the same HTTP method as the primary request (hx-get
,hx-post
, etc.). However, there are cases where developers may need to include specific data as query parameters while making aPOST
request, or vice versa. This lack of flexibility often requires workarounds such as manually constructing URLs or modifying requests with JavaScript.Feature Request
Introduce a way to specify the HTTP method explicitly for
hx-include
andhx-vals
. This would allow certain values to be included in the query string (GET
) while keeping others in the request body (POST
).Proposed Syntax:
hx-include="#filters get"
→ Includes#filters
fields as query parameters.hx-include="#extra post"
→ Ensures#extra
fields are included in the request body.hx-vals="{ key: 'value' } get"
→ Appendskey=value
as a query parameter.hx-vals="{ extra: '123' } post"
→ Sendsextra=123
in the request body.Expected Behavior
With
hx-include="#filters get"
andhx-vals="{ key: 'value' } get"
, anhx-post
request would be transformed into:Use Case
A common scenario where this is useful is when updating a table’s data while maintaining filter parameters in the URL. For example:
Here,
name=John
is sent in the request body, whilesearch=abc
,category=1
, andkey=value
are included in the query string. This makes it possible to refresh the table with updated data while preserving filter state without requiring JavaScript workarounds.The text was updated successfully, but these errors were encountered: