Answers.Body: <p>My suggestion would be to give the <code>Select All Values</code> checkbox a unique name. That way, you can easily detect whether it was selected or not. You should also break <code>dropdown_field</code> out into 2 variables to avoid confusion.</p>
  <pre><code>{% set select_all_values = select_all_values ?? false
  
  {% set dropdown_field_options = ['dropdown_value_1', 'dropdown_value_2', 'dropdown_value_3', 'dropdown_value_4', 'dropdown_value_5'] %}
  {% set params = {section: 'section_1'} %}
  
  {% if not select_all_values %}
      {% set params = params|merge({dropdown_field: dropdown_field} %}
  {% endif %}
  
  {% set entryQuery = craft.entries(params) %}
  
  
  &lt;div s-replace=&quot;#results&quot;&gt;
      &lt;div&gt;
          &lt;input sprig type=&quot;checkbox&quot; name=&quot;select_all_values&quot; id=&quot;dropdown_value_all&quot; value=&quot;1&quot; {{ select_all_values ? 'checked disabled' : '' }}&gt;
          &lt;label for=&quot;dropdown_value_all&quot;&gt;
              Select All Values
          &lt;/label&gt;
      &lt;/div&gt;
      {% for value in dropdown_field_options %}
      &lt;div&gt;
          &lt;input sprig type=&quot;checkbox&quot; name=&quot;dropdown_field[]&quot; id=&quot;{{ value }}&quot; value=&quot;{{ value }}&quot; {{ value in dropdown_field ? 'checked' : '' }}&gt;
          &lt;label for=&quot;{{ value }}&quot;&gt;
              {{ value }}
          &lt;/label&gt;
      &lt;/div&gt;
      {% endfor %}
  &lt;/div&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-14T19:31:02.410Z
Answers.Text: Thank you Ben!!
Answers.UserDisplayName: HendrikEng
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-13T22:33:50.610Z
Answers.LastActivityDate: 2021-03-13T22:33:50.610Z
Answers.UserDisplayName: Ben Croker
Body: <p>I am having a question regarding Sprig.
  I do want to filter my entries for values that are defined in a dropdown field (example below is simplified).
  It does work to the point where I want to filter all entries for all values, on page load all single checkboxes should be checked as well as the <code>all</code> checkbox.
  The problem is that Sprigs AJAX request sends a single request for each single filter e.g.:</p>
  <pre><code>dropdown_field[]: dropdown_value_1
  dropdown_field[]: dropdown_value_2
  </code></pre>
  <p>but for the all filter, and e.g. one checkbox it will be:</p>
  <pre><code>dropdown_field[]: dropdown_value_1, dropdown_value_2 .....
  dropdown_field[]: dropdown_value_2
  </code></pre>
  <p>Unchecking the <code>all</code> checkbox will not empty the array, what it should.</p>
  <p>That will cause the single filters not to work if <code>all</code> is checked. How can I make sure that the query request will be one array for all values instead of multiple query requests?</p>
  <p>All Filters should be activated on load, the <code>all</code> filter would be disabled then. If a single checkbox is checked <code>all</code> shouldn't be checked (array has to be empty except the single value).</p>
  <pre><code>{% set dropdown_field = ['dropdown_value_1', 'dropdown_value_2', 'dropdown_value_3', 'dropdown_value_4', 'dropdown_value_5'] %}
  
  {% set entryQuery = craft.entries({
      dropdown_field: dropdown_field,
      section: 'section_1',
  }) %}
  
  &lt;div s-replace=&quot;#results&quot;&gt;
      &lt;div&gt;
          &lt;input sprig type=&quot;checkbox&quot; name=&quot;dropdown_field[]&quot; id=&quot;dropdown_value_all&quot; value=&quot;&quot; {{ dropdown_field|length &gt;= 5 ? 'checked disabled' : '' }}&gt;
          &lt;label for=&quot;dropdown_value_all&quot;&gt;
              Select All Values
          &lt;/label&gt;
      &lt;/div&gt;
      {% for value in dropdown_field %}
      &lt;div&gt;
          &lt;input sprig type=&quot;checkbox&quot; name=&quot;dropdown_field[]&quot; id=&quot;{{ value }}&quot; value=&quot;{{ value }}&quot; {{ value in dropdown_field ? 'checked' : '' }}&gt;
          &lt;label for=&quot;{{ value }}&quot;&gt;
              {{ value }}
          &lt;/label&gt;
      &lt;/div&gt;
      {% endfor %}
  &lt;/div&gt;
  
  &lt;div id=&quot;results&quot;&gt;
      &lt;ul&gt;
      {% for entry in entryQuery %}
          &lt;li&gt;{{ entry.title }}&lt;/li&gt;
      {% endfor %}
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Thank you!</p>
  
Tags: <search><filter><query><checkboxes><plugin-sprig>
Title: Sprig - Filter entries by custom field checkbox values, separate values as well as all values
ThreadText: # Sprig - Filter entries by custom field checkbox values, separate values as well as all values
  
  (Asked by: username_0 on 2021-03-13)
  
  I am having a question regarding Sprig.
  I do want to filter my entries for values that are defined in a dropdown field (example below is simplified).
  It does work to the point where I want to filter all entries for all values, on page load all single checkboxes should be checked as well as the `all` checkbox.
  The problem is that Sprigs AJAX request sends a single request for each single filter e.g.:
  
  ```
  dropdown_field[]: dropdown_value_1
  dropdown_field[]: dropdown_value_2
  
  ```
  
  but for the all filter, and e.g. one checkbox it will be:
  
  ```
  dropdown_field[]: dropdown_value_1, dropdown_value_2 .....
  dropdown_field[]: dropdown_value_2
  
  ```
  
  Unchecking the `all` checkbox will not empty the array, what it should.
  
  That will cause the single filters not to work if `all` is checked. How can I make sure that the query request will be one array for all values instead of multiple query requests?
  
  All Filters should be activated on load, the `all` filter would be disabled then. If a single checkbox is checked `all` shouldn't be checked (array has to be empty except the single value).
  
  ```
  {% set dropdown_field = ['dropdown_value_1', 'dropdown_value_2', 'dropdown_value_3', 'dropdown_value_4', 'dropdown_value_5'] %}
  
  {% set entryQuery = craft.entries({
      dropdown_field: dropdown_field,
      section: 'section_1',
  }) %}
  
  <div s-replace="#results">
      <div>
          <input sprig type="checkbox" name="dropdown_field[]" id="dropdown_value_all" value="" {{ dropdown_field|length >= 5 ? 'checked disabled' : '' }}>
          <label for="dropdown_value_all">
              Select All Values
          </label>
      </div>
      {% for value in dropdown_field %}
      <div>
          <input sprig type="checkbox" name="dropdown_field[]" id="{{ value }}" value="{{ value }}" {{ value in dropdown_field ? 'checked' : '' }}>
          <label for="{{ value }}">
              {{ value }}
          </label>
      </div>
      {% endfor %}
  </div>
  
  <div id="results">
      <ul>
      {% for entry in entryQuery %}
          <li>{{ entry.title }}</li>
      {% endfor %}
      </ul>
  </div>
  
  ```
  
  Thank you!
  
  **Tags:** search, filter, query, checkboxes, plugin-sprig
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-03-13. Score: 2 | Accepted answer
  
  My suggestion would be to give the `Select All Values` checkbox a unique name. That way, you can easily detect whether it was selected or not. You should also break `dropdown_field` out into 2 variables to avoid confusion.
  
  ```
  {% set select_all_values = select_all_values ?? false
  
  {% set dropdown_field_options = ['dropdown_value_1', 'dropdown_value_2', 'dropdown_value_3', 'dropdown_value_4', 'dropdown_value_5'] %}
  {% set params = {section: 'section_1'} %}
  
  {% if not select_all_values %}
      {% set params = params|merge({dropdown_field: dropdown_field} %}
  {% endif %}
  
  {% set entryQuery = craft.entries(params) %}
  
  <div s-replace="#results">
      <div>
          <input sprig type="checkbox" name="select_all_values" id="dropdown_value_all" value="1" {{ select_all_values ? 'checked disabled' : '' }}>
          <label for="dropdown_value_all">
              Select All Values
          </label>
      </div>
      {% for value in dropdown_field_options %}
      <div>
          <input sprig type="checkbox" name="dropdown_field[]" id="{{ value }}" value="{{ value }}" {{ value in dropdown_field ? 'checked' : '' }}>
          <label for="{{ value }}">
              {{ value }}
          </label>
      </div>
      {% endfor %}
  </div>
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you Ben!!  
  
  ---
  
  