CMS Development

unicorndev
Participant

DropDown for Country List not Showing from HubDB

Hello there, I created a small dropdown of countries listed for representatives in the area. I did this for representatives in the US with the same code and it worked correctly. I may not be filtering the country code correctly and was wondering if anyone can double check my code for me?

 

The name of the column label in my database is 'country' so I found it odd it's not 'matching up' for me.

 

https://21908587.hs-sites.com/uson-local-support-0

Here is my mock site. Drop down works for 'Show All" but the countrie reps don't pop up and says theres no listings for that search. Thank you ! 🙂

{% set int_country_ID = 1 %}

<!-- set the filter -->
<div>

  
<form id="form_id" method="get">
    <div>
        <h4>FILTER BY COUNTRY: </h4>
        <select name="country" form="form_id" onChange="this.form.submit()">
            <option value="show-all">Show All</option>
            {% set countrys = hubdb_table_column(5422908, "country").options %}
            {% for choice in countrys %}
                {% set country_list = country_list~choice.id|list%}
                {% if choice.id == request.query_dict.country%}
                    <option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
                {% else %}
                    <option value="{{ choice.id }}">{{ choice.name }}</option>
                {% endif %}
            {% endfor %}
        </select>
    </div>
  
      <div>
        <input name="name" type="text" id="search-by" class="autocomplete" placeholder="Search by name...">
        
    </div>
        <input id="submit-button" type="submit" value="search">
  
  <input type="button" onclick="location.href='http://21908587.hs-sites.com/uson-local-support-0';" value="Show All" />
  <input type="button" onclick="location.href='https://info.godivassecretwigs.com/find-a-consultant';" value="View United States Consultants" />
    
</form>
</div>

<!-- sets the different query parameters using submitted input for hubdb query -->
{% set queryparam = "" %}
{% if request.query_dict.country in ["1", "2", "3", "4", "5", "6"] and request.query_dict.name == "" %}
    {% set queryparam = queryparam ~ "&country="~request.query_dict.country|urlencode %}
{% endif %}
{% if request.query_dict.country in ["1", "2", "3", "4", "5", "6"] and request.query_dict.name != "" %}
    {% set queryparam = queryparam~"&country="~request.query_dict.country|urlencode~"&zip__icontains="~request.query_dict.zip|urlencode %}
{% endif %}
{% if request.query_dict.country == "show-all" and request.query_dict.name != "" %}
    {% set queryparam = queryparam~"&name__icontains="~request.query_dict.name|urlencode %}
{% endif %}



{% set table = hubdb_table_rows(5422908, queryparam) %}





<!-- Check if table exists, set sort by country -->
{% if table == [] %}
    <p class='align-center'>Sorry, no listings found for that search. Try changing your filter and search again.</p>
{% else %}
  {% for row in table|sort(False, False, 'country') %}

<div class="consultant-listing">
<h2>{{ row["name"] }}</h2>
              <p><b>Locations: {{ row["address"] }} </b></p>

              <div class="information">
                <p>{{row["city"]}}, {{row["country"].name}}</p>
                  {{ row["phone"] }}

              
              <br><a href="{{row["website"]}}">{{row["website"]}}</a> 
                <br><a href="mailto:{{ row["email"] }}">{{ row["email"] }}</a>
                       <div class="location_details">{{ row["location_details"] }}</div>

  </div>
</div>
  {% endfor %}
  {% endif %}

 

0 Upvotes
2 Replies 2
Indra
Guide | Elite Partner
Guide | Elite Partner

DropDown for Country List not Showing from HubDB

Hi @unicorndev,

 

Have you changed the different values for the countries?

Perhaps the array you have created doesn't have the correct ID in it since you go from 1 till 6. ['1' .. '6'].

 

What you can do is view the corresponding ID from the current list you have by display the ID.

{% set countrys = hubdb_table_column(5422908, "country").options %}

 

So instead of doing 

{% if request.query_dict.country in ["1", "2", "3", "4", "5", "6"] and request.query_dict.name == "" %}

 

it's better do make it dynamic like this:

{% set countrys = hubdb_table_column(5422908, "country").options %}
{% if request.query_dict.country in countrys|map('id') %}

 

I also recommend checking out the HubDB documentation and tutorials:

  • HubDB 
  • There was a tutorial about a real Estate. You can ask HubSpot Support if it's still avalible.

Bureau Vet

Did my post solve your question? Help the community by marking it as a solution
Jaycee_Lewis
Community Manager
Community Manager

DropDown for Country List not Showing from HubDB

Hey, @unicorndev 👋 I don't have the answer, but I do have some additional troubleshooting thoughts and questions.

To confirm:

For search, it works when searching by name — Roper returns only Roper, Calti returns only Calti, etc., but searching by county  is where you are having issues, correct? China returns nothing, same for Europe, Canada, and Australia.

For the dropdown issue, it works for China and Canada, but not Europe and Australia, correct? 

Yes:

yes-01.pngyes-02.png

No:

nope-01.png

For the dropdown issue, I believe that is our biggest clue — why is it working 50% of the time?

 

Have a wonderful weekend! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot