Setting instance properties in a list?

I have a list of checkboxes. I want a button that will go through the list and disable or enable them. The disable code is:

def runAction(self, event):
	logger = system.util.getLogger("PERS disable")
			
	logger.info("START")
		
	Parent = self.parent
	EmbeddedView = Parent.getChild("EmbeddedView_Ballot")
	Instances = EmbeddedView.props.params.instances
	
	#Create a dataset of one row	
	Names = []
		 
	# step through the rows
	for instance in Instances:
		instance.enable = False
		logger.info("Instance disable " + str(instance.text))	
		
		
	logger.info("disable complete")

The logger shows it is executing:

The enable property is not being set false:

I think the code is only setting the local variable in the script. It is not actually setting the property on the checkbox instance.

How do I do this?

I think I would handle this with a messageHandler on the embedded view, then the button script would just be:

system.perspective.sendMessage('clearAll',{})
1 Like

That looks to be a flex repeater? On whatever source template/view you are using, you'll need to bind the view parameterenabled to the actual enabled property of the checkboxes.

1 Like

I can't do a hard binding, the list is created dynamically

I don't think that does what I want. I do not want to clear the selections. I want to disable the checkboxes so whatever selections have been made cannot be changed

Okay, small mis-understanding on my part (apparently I can't read). No big.

Same approach.

messageHandler on the embedded view, that will change the enabled bit. Something like:

system.perspective.sendMessage('toggleEnable',{'enable':1})

Just change the payload depending on the need.

Then the messageHandler would be:

def onMessageReceived(self, payload):
	#obviously this needs to actually point at the checkBox
	self.props.enable = payload['enable']
2 Likes

The dynamic list is driving the repeater, the repeater is repeating a view that is defined elsewhere in the project. Somewhere there will be a view that is just a checkbox, and maybe a label. Do the changes I mentioned on that source view, not the view with the flex repeater.

Start by inspecting the CVoz_Ballot_Approval view and see what view its template repeater is using.

1 Like

You have a typo: you're setting enable instead of enabled

The message handler approach is perfect! Thanks Irose!

FWIW also, you should never update your gui props from a script from within a loop like this as it will be slow and users will see the components changing 1-by-1. You should get a copy of the prop into a variable, modify the variable, and only then write it back to the prop at the end. e.g. in this case, write the whole instances list back to the prop.

5 Likes