CMS Development

naixs
Participant | Diamond Partner
Participant | Diamond Partner

How can I set the selected choice to use it like a filter?

SOLVE

<select class="list-city dropdown" name="city">
{% set types = hubdb_table_column(module.hubdbtable_field, "city").options %}
{% for choice in types %}
<option value="{{ choice.name }}">{{ choice.name }}</option>
{% endfor %}
</select>

 

{% set table = hubdb_table_rows(module.hubdbtable_field, 'city=(choice-selected-here)') %}

0 Upvotes
1 Accepted solution
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

How can I set the selected choice to use it like a filter?

SOLVE

It only works if you have your query parameter in the URL that the HubL is looking for. Open the preview URL in a new window, then at the end add your "&name=1" and see if it works.

Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post

4 Replies 4
stefen
Key Advisor | Partner
Key Advisor | Partner

How can I set the selected choice to use it like a filter?

SOLVE

@naixs looks like your using "city" as the name for that form input. If you are using a form the native browser way, it should add a query paremeter to your URL when you submit the form which should look like this example.com/page?city=new%20york

 

You can use HubL to look for that query parameter in the URL when the page refreshes to add the "selected" attribute.

 

Here's what that looks like with your code:

 

<select class="list-city dropdown" name="city">
{% set types = hubdb_table_column(module.hubdbtable_field, "city").options %}
{% for choice in types %}
<option {% if choice.name == request.query_dict.name %}selected{% endif %} value="{{ choice.name }}">{{ choice.name }}</option>
{% endfor %}
</select>

 

 

HubSpot has a great tutorial for a basic HubDB filtering system that you can reference here.

Stefen Phelps, Community Champion, Kelp Web Developer
naixs
Participant | Diamond Partner
Participant | Diamond Partner

How can I set the selected choice to use it like a filter?

SOLVE

Thanks for the answer, I tried with this option but the "if" is not working and didn´t change the selected choiceimage_2020_08_20T14_56_45_481Z.png

 

<div>
<form id="form_id" method="get">
<div>
<h4>FILTER BY LISTING TYPE: </h4>
<select class="list-city dropdown" name="city">
{% set types = hubdb_table_column(module.hubdbtable_field, "city").options %}
{% for choice in types %}
<option {% if choice.name == request.query_dict.name %} selected {% endif %} value="{{ choice.name }}">{{ choice.name }}</option>
{% endfor %}
</select>
</div>

</form>
</div>

0 Upvotes
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

How can I set the selected choice to use it like a filter?

SOLVE

It only works if you have your query parameter in the URL that the HubL is looking for. Open the preview URL in a new window, then at the end add your "&name=1" and see if it works.

Stefen Phelps, Community Champion, Kelp Web Developer
sharonlicari
Community Manager
Community Manager

How can I set the selected choice to use it like a filter?

SOLVE

Hey @naixs 

 

Thank you for sharing this information, I'll tag a few experts could share their knowledge with you.

 

Hey @John @stefen @Jsum  any advice you can give to @naixs ?  

 

Thank you & Happy Friday

Sharon


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




0 Upvotes