htmx icon indicating copy to clipboard operation
htmx copied to clipboard

hx-push-url appends query param multiple times

Open liko28s opened this issue 3 years ago • 2 comments

Hi guys, I'm using Htmx for a single pagination and ordering controls. I'm not using a form, just:

<select  id="select-order-by" name="order_by" class="c-options-select__list" hx-get="" hx-push-url="true" hx-target="body">
    <option class="c-options-select__item"  value="title">A-Z</option>
    <option class="c-options-select__item"  value="-title">Z-A</option>
    <option class="c-options-select__item"  value="created-at">Latest</option>
    <option class="c-options-select__item"  value="-created-at">Older</option>
</select>

But currently htmx is appending the same query param each time i use the select, turning url in something like locahost/?order_by=recent&order_by=title&order_by=-recent

I use hx-push-url to be able to combine with pagination (?page=2&order_by=title).

I need that the query params to remain only once.

I think is not a duplicated of #383

liko28s avatar Dec 02 '21 06:12 liko28s

Hi there,

I think is not a duplicated of https://github.com/bigskysoftware/htmx/issues/383

But have you tried setting hx-get to a non-empty value, like the URL of the endpoint handling your request, with no query param? I'm asking because htmx code explicitly says it takes the full current URL when an empty URL is passed for AJAX request. I see no other explanation.

David-Guillot avatar Apr 18 '22 19:04 David-Guillot

I have the similler issue here

this is my html code

<form  hx-get="/url"
     hx-trigger="changed, change"
     hx-push-url="true"
     id="filters-block">
     ....
</form>

if i opened the page for the first time without any querystring in the url everything works fine but the moment i have an existing value in the url and submit the form again it insted of replaceing the query is just appending to the existing query which cuzing many issue with array fields like checkboxes

for example opening this link /en/show-room?placeIds=1 ==> change the place to 2 the url become /en/show-room?placeIds=1&placeIds=2

hosamre94 avatar Oct 12 '22 08:10 hosamre94