CMS Development

ASpahiu
Membre | Partenaire solutions Gold
Membre | Partenaire solutions Gold

Choice generated dynamically does not support multiple

Résolue

I am trying to create a choice module, that has some options generated dinamically. After creating it, I want to have the possibility to multiple select choices from this, similarly how a choice field works on modules when "Allow selection of multiple options" is activated.  
Code: 
{% choice "multi_choice_field" label="multiple choice" display="select" choices=[ [ "option-1", "Option 1" ], [ "option-2", "Option 2" ] ] multiple=true %}
Is this possible? 
Thanks in advance

0 Votes
1 Solution acceptée
GRajput
Solution
Expert reconnu | Partenaire solutions Gold
Expert reconnu | Partenaire solutions Gold

Choice generated dynamically does not support multiple

Résolue

Hi @ASpahiu 

 

We’ve shared some code with you, including different conditions. Please check it once—hopefully, it will work. If not, kindly share the page with us, and we’ll take a look and provide guidance.

 

Update code:

{% choice "multi_choice_field" label="multiple choice" display="checkbox" <!-- Change display to checkbox for multiple options --> choices=[ [ "option-1", "Option 1" ], [ "option-2", "Option 2" ] ] multiple=true %}

 

If you want to generate options dynamically, you can do so by using HubL loops. Here's an example of how you can generate choices dynamically:

{% set options = [ { "value": "option-1", "label": "Option 1" }, { "value": "option-2", "label": "Option 2" }, { "value": "option-3", "label": "Option 3" } ] %} {% choice "multi_choice_field" label="multiple choice" display="checkbox" multiple=true choices=options %}

 

If you prefer to keep the dropdown style but allow multiple selections, you’ll need to manually adjust the HTML using the select tag and enable multiple selections like this:

 

<select name="multi_choice_field" multiple> {% for option in options %} <option value="{{ option.value }}">{{ option.label }}</option> {% endfor %} </select>

 

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.
Thanks!

 




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting


Voir la solution dans l'envoi d'origine

2 Réponses
ASpahiu
Membre | Partenaire solutions Gold
Membre | Partenaire solutions Gold

Choice generated dynamically does not support multiple

Résolue

Hello @GRajput 
Thanks for following up. 
I have tried this approach earlier and it doesn't work. 
I do not think that what I am trying to do is possible, after confronting official Hubspot Documentation.
On the choice tag, the only parameters that could be added are value and choices, and this means that this dynamically generated choice module doesn't behave like the usual choice field on modules. 
Thanks for reaching out

 

0 Votes
GRajput
Solution
Expert reconnu | Partenaire solutions Gold
Expert reconnu | Partenaire solutions Gold

Choice generated dynamically does not support multiple

Résolue

Hi @ASpahiu 

 

We’ve shared some code with you, including different conditions. Please check it once—hopefully, it will work. If not, kindly share the page with us, and we’ll take a look and provide guidance.

 

Update code:

{% choice "multi_choice_field" label="multiple choice" display="checkbox" <!-- Change display to checkbox for multiple options --> choices=[ [ "option-1", "Option 1" ], [ "option-2", "Option 2" ] ] multiple=true %}

 

If you want to generate options dynamically, you can do so by using HubL loops. Here's an example of how you can generate choices dynamically:

{% set options = [ { "value": "option-1", "label": "Option 1" }, { "value": "option-2", "label": "Option 2" }, { "value": "option-3", "label": "Option 3" } ] %} {% choice "multi_choice_field" label="multiple choice" display="checkbox" multiple=true choices=options %}

 

If you prefer to keep the dropdown style but allow multiple selections, you’ll need to manually adjust the HTML using the select tag and enable multiple selections like this:

 

<select name="multi_choice_field" multiple> {% for option in options %} <option value="{{ option.value }}">{{ option.label }}</option> {% endfor %} </select>

 

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.
Thanks!

 




Gaurav Rajput
Director, MarTech( Growth Natives)

Book a meeting