paoloricciuti / sveltekit-search-params

The easiest way to read and WRITE from query parameters in sveltekit.
https://sveltekit-search-params.netlify.app
MIT License
478 stars 13 forks source link

Remove empty query string. #78

Open sideshot opened 4 months ago

sideshot commented 4 months ago

Describe the bug

How do I get an empty query string off the URL?

Reproduction

Add with data then try to remove.

Logs

No response

paoloricciuti commented 4 months ago

You can set the empty string as default value and use showDefaults: false

sideshot commented 4 months ago

Strange, that is what I'm doing. I saw that suggestion in another issue. Once I select and then deselect, it still ends up with ?filter_category=

    const selected = queryParam(`filter_${section.id}`,ssp.string(''),{
        showDefaults: false
    });
<input
    id={`filter-${section.id}-${optionIdx}`}
    value="{option.value}"
    type="checkbox"
    bind:group={$selected}
    class="h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500"
/>

Any thoughts? Awesome script, by the way.

paoloricciuti commented 4 months ago

I don't think you can use a string to bind to a checkbox group...if you prepare a reproduction I can try to take a look