Hola! ¡Tenemos nuestra Comunidad en Español!

Filtering HubDB Multiselect

Top Contributor

Hi all, I have set up a filter that pulls data from a Hubdb with a 'select' column type.
{% if request.query_dict.type in ["1", "2", "3", "4","5", "6", "7", "8", "9", "10"] %}

 

My question is how do I do a similar thing with a 'multiselect' column type? (edited)

 

Thanks

Reply
0 Upvotes
5 Replies
Community Manager

Hi @Woodsy could you please share a link to the page you are working on?

Reply
0 Upvotes
Highlighted
Top Contributor

Hi @roisinkirby I need to replace the second filter query so that the second filter dropdown only returns Hubdb entries that contain that Hubdb multi-select tag.
Here is my current code:

 

    <form id="form_id" method="get">

      <div>
        <h4>Filter by resource type: </h4>
        <select name="type" form="form_id" onChange="this.form.submit()">
          <option value="show-all">Show All</option>
          {% set types = hubdb_table_column(848813, "resource_type").options %}
          {% for choice in types %}
          {% set type_list = type_list~choice.id|list%}
          {% if choice.id == request.query_dict.type%}
          <option selected="selected" value="{{ choice.id }}" onclick="resourceFilter()">{{ choice.name }}</option>
          {% else %}
          <option value="{{ choice.id }}">{{ choice.name }}</option>
          {% endif %}
          {% endfor %}
        </select>
      </div>
      
      <div>
        <h4>Filter by topic area: </h4>
        <select name="area" form="form_id" onChange="this.form.submit()">
          <option value="show-all">Show All</option>
          {% set areas = hubdb_table_column(848813, "focus_area").options %}
          {% for choice in areas %}
          {% set area_list = area_list~choice.id|list%}
          {% if choice.id == request.query_dict.area%}
          <option selected="selected" value="{{ choice.id }}" onclick="resourceFilter()">{{ choice.name }}</option>
          {% else %}
          <option value="{{ choice.id }}">{{ choice.name }}</option>
          {% endif %}
          {% endfor %}
        </select>
      </div>
      

      
    </form>
  </div>
  


{% set queryparam = "&orderBy=resource_order"~"&resource_order__gt=0" %}
{% if request.query_dict.type in ["1", "2", "3", "4","5", "6", "7", "8", "9", "10"] %}
    {% set queryparam = queryparam ~ "&resource_type="~request.query_dict.type|urlencode %}
{% endif %}
{% if request.query_dict.type == "show-all" %}
    {% set queryparam = queryparam %}
{% endif %}
  
 <!-- Multi-select hubdb query -->
{% set areaquery = "&orderBy=resource_order"~"&resource_order__gt=0" %}
{% if request.query_dict.area in ["1", "2", "3", "4","5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"] %}
    {% set areaquery = areaquery ~ "&focus_area="~request.query_dict.area|urlencode %}
{% endif %}
{% if request.query_dict.area == "show-all" %}
    {% set areaquery = areaquery %}
{% endif %}

 

Reply
0 Upvotes
Community Manager

Thanks for sharing @Woodsy@tjoyce is this something you could lend your expertise to? Thanks!

Reply
0 Upvotes
Top Contributor

Hi @roisinkirby did you have any ideas around how I could tackle multi-select HubDB filtering?

 

Thanks

Reply
0 Upvotes
Occasional Contributor

You have an easy solution if you add this sufix to your variable: __contains

Reply
0 Upvotes