Hi there, have been taking some inspiration from https://community.hubspot.com/t5/CMS-Development/Add-a-filter-dropdown-to-a-listing-page-containing-HubDB-similar/m-p/339886 to create a simple filter to filter the results in https://8830131.hs-sites.com/timetable-with-filter by things such as mode. I’ve been able to get the dropdown to populate and url to change but not been able to get the results to actually change based on this.
See code for module:
<h2>2023 Timetable</h2>
<div>
<form id="form_id" method="get">
<div>
<h4>Filter by Delivery Mode:</h4>
<select id="delivery_mode" class="delivery_mode" name="delivery_mode">
<option selected value="show-all">Show all</option>
{% set types = hubdb_table_column(5886054, "delivery_mode").options %}
{% for choice in types %}
<option {% if choice.name == request.query_dict.delivery_mode %} selected {% endif %} value="{{ choice.name }}">{{ choice.name }}</option>
{% endfor %}
</select>
</div>
</form>
</div>
<!-- sets the different query parameters using submitted input for hubdb query -->
{% set queryparam = "" %}
{% if request.query_dict.delivery_mode in ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"] %}
{% set queryparam = queryparam ~ "&delivery_mode="~request.query_dict.delivery_mode|urlencode %}
{% endif %}
{% if request.query_dict.delivery_mode == "show-all" %}
{% set queryparam = queryparam %}
{% endif %}
{% for row in hubdb_table_rows(5886054, "&orderBy=intake_period" ~ queryparam) %}
<div class="card">
<h6 class="heading">
{{ row.subject_name }}
</h6>
<p>
<strong>Intake Period:</strong> {{ row.intake_period.name }}<br>
<strong>Campus:</strong> {% for campus_availability in row.campus_availability %}
{{ campus_availability.name }}{% endfor %}<br>
<strong>Associated Courses:</strong> {% for associated_course in row.associated_course %}
{{ associated_course.name }}{% if not loop.last %}, {% endif %}{% endfor %}<br>
{% if row.intensive_dates %}
<strong>Intensive or staggered class dates:</strong> {{row.intensive_dates}}<br>
{% endif %}
{% if row.class_time %}
<strong>Class time (by host):</strong> {{row.class_time}}<br>
{% endif %}
{% if row.class_frequency %}
<strong>Frequency:</strong> {% for class_frequency in row.class_frequency %} {{class_frequency.name}}{% endfor %}<br>
{% endif %}
{% if row.delivery_mode %}
<strong>Mode:</strong> {{row.delivery_mode.name}}<br>
{% endif %}
{% if row.prerequisites %}
<strong>Prerequisites:</strong> {{row.prerequisites}}<br>
{% endif %}
{% if row.additional_notes %}
<strong>Notes:</strong> {{row.additional_notes}}
{% endif %}
</p>
</div>
{% endfor %}
<script>
const deliveryModeFilterElement = document.getElementById('delivery_mode');
let deliveryModeFilter = ''; // Initialize the filter value
deliveryModeFilterElement.addEventListener('change', function(event) {
deliveryModeFilter = event.target.value; // Update the filter value
// Perform any additional logic or actions based on the new filter value
// Trigger form submission to apply the filter
document.getElementById('form_id').submit();
});
</script>
Is someone able to help with why this might be broken? I’ve probably overlooked something pretty trivial I assume.
Cheers.