I have a repeating block that I need to pre set the number of repeats based on a dropdown field selection, my attempt to place the following code replicated from one of my composer forms doesn't work. Is there a way to do this is maestro?
var num = (data.howManyAdditionalProperties == "3 or more" ? 3 : Number(data.howManyAdditionalProperties ));
var repeat = Form.getItemFromPath(Form.getItemProperty("data.addFormgetitempropertydatacontentitemlabel3","repeatLink"));
Ryan Mazi ThomasYou won't necessarily need the form.setInstanceCount call
However, to ensure that the object is available, we use a calculate rule after the repeat object in the hierarchy that just does this using a node array:
No need to use setinstancecount
As of Maestro 5.0.18, you can set the instance count of a repeat with the following method.
The first parameter can be the item or the "data path string" of the item. The second is the data path of the repeat (which will be an array) and the last is the desired count you want the repeat to be modified to.
Additionally if you want to populate this repeat with some data you can do it with the Util.addRepeatContent method (This has been tested on a page load rule):
I tried the approach above but whenever I click the "Util.addRepeatContent" button I get the following error:
I double checked and my "Form.items.davidRepeat" is of type "repeat". I noticed that the "Form.items.davidRepeat" has a property "repeatingData: true". It seems that the function "addRepeatContent()" has the following line causing the error:
I'm not sure why this is the case however. Is there something I am doing wrong or should be doing differently?
I am doing something similar and have this working. Here is my code:
This works fine when the code is triggered via a button click rule, however I need this to be triggered on page load instead. When I try this I get the following error in the console:
Please can you advise?
Hey Jordan, you kind of had the right functions but you are using them in the wrong way.
Form.getItemFromPath expects a data path as a string (i.e. what you get when you double click a component to add its data path to the script). You will need to call the setInstanceCount function on the result of that call.
Assuming the field Id of your repeat component was 'content2' and the number of repeats you want to set is contained in a field called repeatCount, your script should be as follows:
I also would recommend you take a look at this article:
Did you get this working Jordan?