Open BoPeng opened 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.
The gotta I had was using
hx-vals="{'key': 'value'}"
which was silently ignored. Only
hx-vals='{"key": "value"}'
was valid.
The first of both is not valid JSON.
It must be quoted by "
It would be useful to add some examples of use, for instance with Javascript functions, I.e.:
hx-vals="js:{width: getWidth()}"
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.
Looking forward for this feature too. For my purpose, I created an hidden input field to make the job done.
@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
…
PRs to improve documentation are always welcome if you feel like it btw!
It took me two days to debug this due to the same issue with hx-post. You really should make this clear.
I was trying to confirm if
hx-vals
can be used forhx-post
and noticed thathx-vals
does not mentionhx-post
. All examples usehx-get
.hx-post
does not mentionhx-vals
(orhx-include
).parameters
mentionshx-include
but nothx-vals
.It would be helpful to clarify the use of
hx-vals
withhx-post
since it can be easier to use thanhx-include
in some scenarios.