I am using the Sprig plugin to filter news entries on a news overview page. I have three checkboxes for the categories related to the news entries.
I have the page working for the basic functions by adapting code used on the Sprigboard.
But the page won't let me select multiple checkboxes. I can't figure out how to make Sprig respect all checkboxes and push the selection to the url.
I have previously done this using vanilla javascript, but I wonder if such a feature could be solved elegantly using Sprig.
Category checkboxes:
{% for category in craft.categories().group('news').all() %}
<li class="filter--content--item {{ category.id in newsCat ? 'selected' : '' }}">
<input sprig type="checkbox" class="filter_checkbox" name="newsCat" id="checkbox_{{ category.id }}" value="{{ category.id }}" {{ category.id in newsCat ? 'checked' : '' }}>
<label id="label_{{ category.id }}" class="newsCatLabel" for="checkbox_{{ category.id }}">
{{ category.title }}
</label>
</li>
{% endfor %}
Search query:
{% set newsCat = newsCat ?? '' %}
{% set relatedTo = newsCat ? relatedTo|merge([newsCat]) : relatedTo %}
{% set entryQuery = craft.entries
.section('news')
.limit(10)
.relatedTo(relatedTo)
.search(search)
%}
(...)
{% do sprig.pushUrl('?' ~ {page: page, newsCat: newsCat}|url_encode) %}