How to filter entries by checkboxes using Sprig 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() %}
  &lt;li class=&quot;filter--content--item {{ category.id in newsCat ? 'selected' : '' }}&quot;&gt;
      &lt;input sprig type=&quot;checkbox&quot; class=&quot;filter_checkbox&quot; name=&quot;newsCat&quot; id=&quot;checkbox_{{ category.id }}&quot; value=&quot;{{ category.id }}&quot; {{ category.id in newsCat ? 'checked' : '' }}&gt;
      &lt;label id=&quot;label_{{ category.id }}&quot; class=&quot;newsCatLabel&quot; for=&quot;checkbox_{{ category.id }}&quot;&gt;
          {{ category.title }}
      &lt;/label&gt;
  &lt;/li&gt;
  {% 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) %}
Checkbox input field names should be in array format (not specific to Sprig), so I expect this should work.
&lt;input sprig type=&quot;checkbox&quot; class=&quot;filter_checkbox&quot; name=&quot;newsCat[]&quot; id=&quot;checkbox_{{ category.id }}&quot; value=&quot;{{ category.id }}&quot; {{ category.id in newsCat ? 'checked' : '' }}&gt;