- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How would you limit the number of choices in select element
SOLVENov 14, 2020 3:36 PM
Hello!
I'm building a module but got stuck, I have a hubdb with a column of the type select and this column have 5 choices and I would like to have a select filter in my custom module but I would only wish to display 3 of those 5 choices. How would you go about doing that? Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
Nov 16, 2020 4:52 AM
Hi @AminWejebe,
Do you want to display 3 specific choices, or any 3 (i.e. the first 3). If any will do, you could add an if statement in your for loop like:
{% set choices = hubdb_table_column(table_id, "choices").options %}
<select id="myFilter">
<option selected="selected" value="all">Choose an option</option>
{% for item in options %}
{% if loop.index <= 3 %}
<option value="{{item}}">{{item}}</option>
{% endif %}
{% endfor %}
</select>
But I could be more helpful if you copy/paste your code, as the above is assuming you're pulling the choices directly from the HubDB.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content