HubSpot Ideas

Captshawn

Add the option to create repeated fields in custom widgets

One of the biggest oversights in the COS is that it's very difficult to create looped content. As far as I'm aware, the only thing that lets you do a loop is a slider (if you use export_to_template_context), which has a limited number of fields per iteration.

Consider this simple case: I want to create a custom widget where the user can create an arbitrary number of buttons. Each button has a link, text, and a few style options. Currently , they way I would have to do that is to decide what the most buttons I would ever need is, then add that number of each field (for example, five links, five button texts, five style drop-downs, and then distinct markup for all five). Obviously, a very tedious process. And if I want six for some reason, I have to go back and edit the module.

So, here's how I envision this working. First, add a new option to the custom widget editor to create "field groups". Field groups could contain any number of other fields (perhaps even their own child field groups, because why not?), and would have their own labels, names, and description fields. Then, the person using the page editor would be presented with those fields grouped together visually, with add and remove buttons. Clicking add would create a fresh copy of all the fields in the group, clicking remove would remove that item in the group. Then, in the template, you would have the ability to iterate through items in the group with a for loop. Something like this:

{% for button in widget.field_group_name %}
<a href="{{ button.link }}" class="{{ button.style }}">{{ button.text }}</a>
{% endfor %}

The user can have as many buttons as they please, the page editor doesn't get clogged with useless fields, and the code remains simple and easy to maintain. This would give developers a lot of control over presentation without sacrificing ease of use for the page editor. I really can't emphasize enough how much this would simplify certain aspects of template building.

HubSpot Updates
Re: Add the option to create repeated fields in custom widgets - changed to: Delivered
November 29, 2018 01:07 PM

In Beta
October 23, 2017 01:09 PM

In Planning
June 22, 2017 10:55 AM

3 Replies
kleonard
HubSpot Product Team
 
kleonard
HubSpot Product Team
 
mherzog
HubSpot Product Team