I'm using the real estate example code to build out my own custom module for filtering my customers page based on the type of customer they are.
The problem is that my customers can be many types. In my case a customer can be both a customer that fits the "marketing" category and the "corporate archive" category.
I've built multiple columns to house all the various customer types and checked the box for the customers in my table. Some fit one column while others fit two or more.
In the real estate example you filter through the results based on a drop down menu. I'm wondering how we can filter with checkboxes instead...
Here is my sample code (with fake HubDB ID):
<!-- set the filter by drop down, search bar, and submit button -->
<div> <form id="form_id" method="get">
<div> <h4>FILTER BY CUSTOMER TYPE: </h4> <input type="checkbox" name="type" form="form_id" onChange="this.form.submit()"> {% set customer_types = hubdb_table_column(12345, "marketing").options %} {% for choice in types %} {% set type_list = type_list~choice.id|marketing%} {% if choice.id == request.query_dict.type%} <option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option> {% else %} <option value="{{ choice.id }}">{{ choice.name }}</option> {% endif %} {% endfor %} </input> </div>
</form> </div>
<!-- sets the different query parameters using submitted input for hubdb query --> {% set queryparam = "" %} {% if request.query_dict.type in ["4", "5", "6", "7", "8", "9", "10", "11", "12"] %} {% set queryparam = queryparam ~ "&type="~request.query_dict.type|urlencode %} {% endif %} {% if request.query_dict.type == "show-all" %} {% set queryparam = queryparam %} {% endif %}
{% set table = hubdb_table_rows(12345, queryparam) %}
{% if table == [] %} <p class='align-center'>Sorry, no listings found for that Search. Try changing your fiter and search again.</p> {% else %} {% for row in table %} <div> <div class="{{ row["type"].name }}"> <div><img src="{{ row["customer_image"].url}}"></div> <div style="width: {{ widget.width }}px; height: {{ widget.height }}px; background: {{ widget.color }}; display: block; margin: {{ widget.margin }};"></div> <div> <p>{{ row["customer_description"] }}</p> </div> </div> </div> {% endfor %} {% endif %}
How do I write the filter query for checkboxes instead of a drop down menu? Do I need to set a parameter like "type_list" for every column and write multiple If / Else statements?...