hubdb column in as a choice dropdown in custom module

SOLVE
Highlighted
Top Contributor

Can anyone tell me how to create a HubDB filter as a "choice field" in a custom module instead of filtering on the page itself (like the one on this page -http://www.alignex.com/training-classes)?

 

What does the "value" for the choices in the widget need to be so it reference a column and drop down choice in a HubDB table.

 

Would it be something like this or does the table id need to be listed here rather than in the code?

 

Widget Name: {{ widget.select_course }}

Value: "<Insert HubDB Column Name>=1"   Label:"3D CAD"

Value: "select_course=2"   Label:"Simulation"

Value: "select_course=3"   Label:"Electrical"

 

Where do you insert {{ widget.select_course }} into the code so it is dynamic based on the course that meets the "Value" selected?

 

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Top Contributor

@scottrief - I just had a breakthrough on this! Figured I would share if you are still interested.

 

These are my three choice options I put into the custom module choice field. Note the red 1, 2 and 3 are the option ids that correspond to the column choices in my hubdb table. Hope this helps! 

 

{% set queryparam = "&orderBy=date&course=1" %}

{% for row in hubdb_table_rows(<tableId>, queryparam) %}
{% if (row['date']|datetimeformat('%j'))>=(local_dt|datetimeformat('%j'))%}
  <p><strong>Course Name: </strong>{{ row["course"].name }} <br>
  <strong>Date: </strong>{{ row.date|datetimeformat('%A, %B %e, %Y') }}<br> 
  <strong>Location:</strong> {{ row.class_location }}</p>
{% endif %}
{% endfor %}


{% set queryparam = "&orderBy=date&course=2" %}

{% for row in hubdb_table_rows(<tableId>, queryparam) %}
{% if (row['date']|datetimeformat('%j'))>=(local_dt|datetimeformat('%j'))%}
  <p><strong>Course Name: </strong>{{ row["course"].name }} <br>
  <strong>Date: </strong>{{ row.date|datetimeformat('%A, %B %e, %Y') }}<br> 
  <strong>Location:</strong> {{ row.class_location }}</p>
{% endif %}
{% endfor %}


{% set queryparam = "&orderBy=date&course=3" %}

{% for row in hubdb_table_rows(<tableId>, queryparam) %}
{% if (row['date']|datetimeformat('%j'))>=(local_dt|datetimeformat('%j'))%}
  <p><strong>Course Name: </strong>{{ row["course"].name }} <br>
  <strong>Date: </strong>{{ row.date|datetimeformat('%A, %B %e, %Y') }}<br> 
  <strong>Location:</strong> {{ row.class_location }}</p>
{% endif %}
{% endfor %}

 

Reply
0 Upvotes
3 Replies 3
Highlighted
New Contributor

Were you able to figure this out? I have a similar need for use in a Custom Module.

Reply
0 Upvotes
Highlighted
Top Contributor

Hi @scottrief,

 

No I wasn't able to figure this out. I was told in a different post to try something like this... but still wasn't able to make it work. Maybe you could try?

 

{% set col = hubdb_table_column (674971, <columnId>) %} 

{% set select_course = col.getOptionByName("Essentials") %}

{{ select_course }}

 

Reply
0 Upvotes
Highlighted
Top Contributor

@scottrief - I just had a breakthrough on this! Figured I would share if you are still interested.

 

These are my three choice options I put into the custom module choice field. Note the red 1, 2 and 3 are the option ids that correspond to the column choices in my hubdb table. Hope this helps! 

 

{% set queryparam = "&orderBy=date&course=1" %}

{% for row in hubdb_table_rows(<tableId>, queryparam) %}
{% if (row['date']|datetimeformat('%j'))>=(local_dt|datetimeformat('%j'))%}
  <p><strong>Course Name: </strong>{{ row["course"].name }} <br>
  <strong>Date: </strong>{{ row.date|datetimeformat('%A, %B %e, %Y') }}<br> 
  <strong>Location:</strong> {{ row.class_location }}</p>
{% endif %}
{% endfor %}


{% set queryparam = "&orderBy=date&course=2" %}

{% for row in hubdb_table_rows(<tableId>, queryparam) %}
{% if (row['date']|datetimeformat('%j'))>=(local_dt|datetimeformat('%j'))%}
  <p><strong>Course Name: </strong>{{ row["course"].name }} <br>
  <strong>Date: </strong>{{ row.date|datetimeformat('%A, %B %e, %Y') }}<br> 
  <strong>Location:</strong> {{ row.class_location }}</p>
{% endif %}
{% endfor %}


{% set queryparam = "&orderBy=date&course=3" %}

{% for row in hubdb_table_rows(<tableId>, queryparam) %}
{% if (row['date']|datetimeformat('%j'))>=(local_dt|datetimeformat('%j'))%}
  <p><strong>Course Name: </strong>{{ row["course"].name }} <br>
  <strong>Date: </strong>{{ row.date|datetimeformat('%A, %B %e, %Y') }}<br> 
  <strong>Location:</strong> {{ row.class_location }}</p>
{% endif %}
{% endfor %}

 

Reply
0 Upvotes