CMS Development

AminWejebe
Participante

How would you limit the number of choices in select element

resolver

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 

0 Me gusta
1 Soluciones aceptada
piersg
Solución
Asesor destacado

How would you limit the number of choices in select element

resolver

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.

Ver la solución en mensaje original publicado

1 Respuesta 1
piersg
Solución
Asesor destacado

How would you limit the number of choices in select element

resolver

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.