hx-vals with an array and the resulting url string #3327
Closed
marcus-at-localhost
started this conversation in
General
Replies: 1 comment
-
|
ok, I think I got it. I check if an element with the ['data-attribute-id'] attribute (a button in my case) initiated the request. let handle = function (evt) {
if (evt.detail.elt.hasAttribute('data-attribute-id')) {
const path = evt.detail.path.split("?")[0];
// Remove empty elements from parameters
for (const key in evt.detail.parameters) {
if (!evt.detail.parameters[key] || (Array.isArray(evt.detail.parameters[key]) && !evt.detail.parameters[key].length)) {
delete evt.detail.parameters[key];
}
}
// Update the path with new parameters
const searchParams = Qs.stringify(evt.detail.parameters, { arrayFormat: 'brackets' });
evt.detail.path = `${path}?${searchParams}`;
delete evt.detail.parameters
}
};
document.body.addEventListener("htmx:configRequest", handle);I might run into some other trouble, but apparently |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm stuck for hours with the following problem:
I'm using
hx-valsto add an array parameter to htmx.get request. Something like:which results in
/example?x=a&x=bbut I need:
/example?x[]=a&x[]=bto capture that with php$_GET['x'][1]for example.The final path is being build here:
htmx/dist/htmx.js
Line 4419 in 407408b
htmx:beforeRequestor something. At least, I found no viable way to manipulate the URL.my plan would be to use a library like https://github.com/ljharb/qs/ to rebuild the url as I need it.
Any idea how to solve this?
Thanks for your time.
This is somewhat related: #966
Beta Was this translation helpful? Give feedback.
All reactions