Solved: Storing author name data in a choice fields returns "Invalid Choices List"


#1

Hello,

I am having problems trying to get a list of others as choices in choice module. I am able to get the list to the point of pulling everything correctly, the only issue is that I get “Invalid Choices List: [Dana Smith]”. Below is the code I am using:

{% set authors_choice = [] %}
{% set author_list = blog_authors('default', 20) %}
{% for author in author_list|sort(False,False,'display_name') %}
    {{ authors_choice.append(author) }}
{% endfor %}
{% choice "author_two" label="Choose A Secondary Author", value="", choices="{{authors_choice}}", export_to_template_context=True %}

If I do it this way, there are no errors, but then it would have to be manually updated:

{% set my_options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] %}`
{% choice "author_two" label="Choose A Secondary Author", value="", choices="{{my_options}}", export_to_template_context=True %}

I’m not sure what the difference in the value list is since it is essentially the same type of data set being used.

Any help would be much appreciated.


#2

@ajlaporte can you post what blog_authors is as well?


#3

@pmanca The code above pulls in a list of blog authors using the blog_authors HubL function (http://designers.hubspot.com/en/docs/hubl/hubl-supported-functions#blog-authors). It’s then setting author_list to the this and using the for loop to go through it. Inside the for loop, I have it appending the author to the authors_choice variable so once the loop is completed, all the authors (limited to 20 in this case) will be in an array for the authors_choice variable.

This array is what is coming back as an Invalid choices list.


#4

@pmanca Honestly, I dont even need to include the author_list portion of code and instead can do this:

{% set authors_choice = [] %}
{% for author in blog_authors('default', 20) %}
    {{ authors_choice.append(author) }}
{% endfor %}
{% choice "author_two" label="Choose A Secondary Author", value="", choices="{{authors_choice}}", export_to_template_context=True %}

Which still results in an Invalid Choices list. If you’d like I can send you the portal ID and link to the template where this is all at so you can see it.


#5

I was able to figure out the issue. It needed to be stored as a value label pair.


#6

@ajlaporte I’m glad you figured it out . Thanks for letting us know the solution


#7

Hi @ajlaporte!

I know this thread is very told, but would you be able to post your solutions for this? I’m trying to do the same basic thing and I haven’t been able to figure out the syntax to pass in the value label pair and to get past the error.

Thank you!