Flex repeater not clearing out dynamic instances, even when written to do so

instance=[] 
instance.append({"instanceStyle": {"classes": ""}, "instancePosition": {},"timezone_description": {}}) 
newList = list(self.getChild("FlexRepeater").props.instances) + [instance]
self.getChild("FlexRepeater").props.instances = 0 self.getChild("FlexRepeater").props.instances = newList

so when i do this script my goal is to dynamically produce instances, but first i want to clear out all the old instances. this code does not work like this which is odd, because if i do just the self.getChild("FlexRepeater").props.instances = 0 portion of the script, i do indeed clear out the instances, and when i do the self.getChild("FlexRepeater").props.instances = newList portion i do indeed update the list.

Where is this script located? What is triggering this script to execute?

# vvv makes an empty list
instance=[]
# vvv places an object into the empty list
instance.append({"instanceStyle": {"classes": ""}, "instancePosition": {},"timezone_description": {}})
# vvv makes a new list which contains all of the instances CURRENTLY in the Flex Repeater AND your new instance/object
newList = list(self.getChild("FlexRepeater").props.instances) + [instance]
# vvv sets the instances prop to be a numeric 0 value (bad idea)
self.getChild("FlexRepeater").props.instances = 0
# vvv sets the instances of the Flex Repeater to be the list which contains the old instances and the new one
self.getChild("FlexRepeater").props.instances = newList

If you goal is to remove the old instances, you should not make a list which contains those instances.

self.getChild("FlexRepeater").props.instances = [{"instanceStyle": {"classes": ""}, "instancePosition": {},"timezone_description": {}}]

If your goal is to reset the existing instances back to some "known" state, you'd need to store the original structure of the instances either within the script or as a property.

it is a message handler being triggered from startup and from a button

i dont want to store instances. i want it when i press a button i drop all instances that are currently in the repeater, and i rebuild new instances of randomly generated users

The code you've supplied will always set the Flex Repeater to have exactly one instance, with a timezone_description parameter which will be passed to the instance, but that object will always be empty.

If you want n number of instances, then you need to append multiple instance objects into your instance variable and then set the instances to this list of multiple instances.

instance=[]
timezone_name_list=[]  # This is unused in your code, so I don't know its purpose
desired_count_of_instances = 5
for x in range(desired_count_of_instances):
 	self.getChild("FlexRepeater").props.instances = []
    instance.append({"instanceStyle": {"classes": ""}, "instancePosition": {},"timezone_description": {}})
    self.getChild("FlexRepeater").props.instances = instance

Please do not edit older posts in significant ways which would alter their information; this makes it difficult to refer back to what you've done in a previous iteration.

sorry buddy i thought i was making it more clear, i felt my initial post was perhaps a bit rushed

the problem with this when i use my button to call it, it does not delete the original set of instances.

so if i have 2 instances already and i want two more, i set the range to 2, and i expect the template repeater to drop the 2 instances it already has, and build two more, but it doesnt.

def runAction(self, event):
	instances=[]
	desired_count_of_instances = 2
	for x in range(desired_count_of_instances):
	    instances.append({"instanceStyle": {"classes": ""}, "instancePosition": {},"input": x})
	self.getSibling("FlexRepeater").props.instances = instances

This code worked for me.

Some notes:

  • Avoid setting properties inside of loops when you can.
  • I've supplied a parameter of my own based on the View I was using, but it doesn't change the functionality of the code.
  • I also renamed the instance variable, just because I always expect lists to reflect multiple values.

Probably just a communication issue, but the script you've been providing could not be based in a Button because Buttons aren't containers and your getChild functions would throw errors. Did you mean that there exists a Button which triggers a Message Handler which lives on the parent of the Flex Repeater?

yes indeed the button does trigger a message handler. i tried testing the message handling by adding a text box and having the script write "populate users successful" into the box. that code works well.

my flex repeater still does not behave appropriately though

instances=[]
timezone_name_list=[]
self.getChild("TextArea_1").props.text = 'populate users successful'
for x in range(12):
	instances.append({"instanceStyle": {"classes": ""}, "instancePosition": {}})
self.getChild("FlexRepeater").props.instances = instance

we write to the box, but the flex repeater will not update.

Not sure if this is a typo or not but in your loop you are using the list

instances.append

but at the end you use "instance"

self.getChild("FlexRepeater").props.instances = instance

you are correct, my whoopsie.

now we still dont work, but i have corrected it to the following:

def onMessageReceived(self, payload):
instances=
timezone_name_list=
self.getChild("TextArea_1").props.text = 'populate users successful'
for x in range(12):
instances.append({"instanceStyle": {"classes": ""}, "instancePosition": {}})
self.getChild("FlexRepeater").props.instances = instances

This logging is nearly useless because you do it before actually setting any instances. The only information you can glean from it is that the script is being executed.

If you aren't able to get the script working you'll need to reach out to Support as the script works for me - even within a message handler.

if you repeatedly hit the button does it produce new results for you? i can get it to work once, but if i hit the button to generate a new user it does not change the user.

	instances=[]
	timezone_name_list=[]
	self.getChild("FlexRepeater").props.instances = []
	for x in range(12):
		instances.append({"instanceStyle": {"classes": ""}, "instancePosition": {}})
	self.getChild("FlexRepeater").props.instances = instances

This code here clears out all existing instances before resetting to 12 empty instances.

i swore i tried that, but you are right my friend, it works. smooth as a hot knife through butter. many thanks to you brother. i appreciate you.

i did have to add a bit more to it for it to work properly, it wouldnt load properly without a sleep.
instances=
timezone_name_list=
self.getChild("FlexRepeater").props.instances =
time.sleep(0.5)

did the trick.