bigskysoftware / htmx

</> htmx - high power tools for HTML
https://htmx.org
Other
38.31k stars 1.31k forks source link

Documentation on the use of hx-vals for hx-post is lacking #1134

Open BoPeng opened 1 year ago

BoPeng commented 1 year ago

I was trying to confirm if hx-vals can be used for hx-post and noticed that

It would be helpful to clarify the use of hx-vals with hx-post since it can be easier to use than hx-include in some scenarios.

corlaez commented 1 year ago

It's a good idea. There are also some gotchas in how hx-vals can send the values as query params or body depending on the verb used. I would prefer I had something like hx-query-vals and hx-body-vals, similar to how we have a header specific attribute. But anyways that's besides the point.

BoPeng commented 1 year ago

The gotta I had was using

hx-vals="{'key': 'value'}"

which was silently ignored. Only

hx-vals='{"key": "value"}'

was valid.

andryyy commented 1 year ago

The first of both is not valid JSON.

It must be quoted by "

migliori commented 1 year ago

It would be useful to add some examples of use, for instance with Javascript functions, I.e.: hx-vals="js:{width: getWidth()}"

jantari commented 1 year ago

The docs for hx-vals mention twice how "by default, the value of hx-vals must be valid JSON".

Ok I understand this default, but I cannot find documentation anywhere on how to change this and allow myself to just POST any plaintext such as hx-vals="rawstring" in the request body? What are the other, non-default options for hx-vals? Is it just either JSON or dynamic js:? If so, the wording could be clearer.

Lord-Y commented 10 months ago

Looking forward for this feature too. For my purpose, I created an hidden input field to make the job done.

odanoburu commented 2 months ago

@Lord-Y The feature is there, just the documentation is missing. I too had gone the hidden input field route before finding out about hx-vals

Telroshan commented 2 months ago

PRs to improve documentation are always welcome if you feel like it btw!

esrid commented 3 weeks ago

It took me two days to debug this due to the same issue with hx-post. You really should make this clear.