View Startup, Enable or disable components

I have View-A that opens a popup on two different events, each event passing a different value to the popup parameter, p1.

If I click a button, I pass value of 0 (zero). If I click on a table row, I pass a value from the table, for example 100.

I would like to enable certain components if the value is 0, and disable them if greater than 0. I have been attempting to use the popup view's onStartup event to check the value of p1, but that gives varying results. Code from this event:

def runAction(self):
	self.getChild("root").getChild("TabContainer").props.currentTabIndex = 0
	if self.params.p1 == 0:
		self.getChild("root").getChild("TabContainer").getChild("flx_General").custom.enable_comp = True
	else:
		self.getChild("root").getChild("TabContainer").getChild("flx_General").custom.enable_comp = False

The components enabled prop are bound to this: custom.enable_comp.

The components seem to alternate enable/disable every couple of clicks on the button, and the same thing with clicking on a table row. So I get inconsistent results. Is the popup view actually firing the start up event every time the popup opens? If so, it seems as if it remembers the previous value, like in a cache or something, ( I have a label bound to p1 so I can see what the value really is and if the components should be enabled or not). If the event does not fire every time the popup opens, then we should fix that :).

The idea is to use the same popup for adding records or viewing an existing record.

I've also tried using the start up event of a nested flex container that specifically holds those components, which is mentioned in the code above as flx_General. And as you can see, there are other tabs with more components that I would also like to do the same. But perhaps I am going about this the wrong way?

What should I look at or change?
Thanks

You may be running into a timing issue in the onStartup() event. There are a couple of things you could do which might improve the operation.

  1. Using long paths to component properties such as self.getChild("root").getChild("TabContainer").props.currentTabIndex gives you a "brittle" structure. It breaks very easily when you move components around or wrap them in a container. Instead, for example, create view.custom.currentTabIndex property and then bind TabContainer's currentTabIndex to the custom property. This should always work.

  2. Do the same with custom.enable_comp. Move it out to view.custom and then you can create a binding to that.

  3. Add some labels to the popup to display the two view variables. That way you can monitor what is happening to the variables.

  4. Are you sure that the popups are closing properly? How are they being closed? Are you passing the popup's ID with the shutdown command?

1 Like

All of this is unnecessary, as you can directly bind flx_General.props.enabled with the following expression:

int(this.view.params.p1) != 0

Never write to a value if you can just bind the relevant property against some known value.

Yes, it is.

Is there any chance you could supply the code you're using to open the Popup (and pass the params)? A lot of times when users hit issues like this it's because sometimes they pass string 0 ("0"), and sometimes they pass a numeric value (0). Your direct check against the numeric 0 could be causing your problem if you're actually passing a string value.

1 Like

I moved both to the view.custom, added another label (already had one) to compare the two custom.props. The view.custom.currentTabIndex is bound to the Tab.props.currentTabIndex. (I may not even need to use this except to make sure the first tab is the one seen when the form opens.)

The popup is closed via the ID sent to open it.

Open:

    popId = "item_details_id"
	popView1 = "Page/inv/ItemDetailsBp_PU"
	system.perspective.openPopup(popId, popView1, params={"p_itemID":self.props.selection.data[0].ItemID, "pu_id":popId, "p_newItem":0}, showCloseIcon = True, resizable = True)

@cmallonee no string O here, value straight from the INT type in the table.
Close:

def runAction(self, event):
	system.perspective.closePopup("item_details_id")

@cmallonee
Instead of this:

int(this.view.params.p1) != 0

I went with this:

if({view.params.p_itemID} > 0, False, True)

to set the value of this: view.custom.enable_comp. This value is changed via the "Edit" button, like a toggle switch:

def runAction(self, event):
	enableComp = self.view.custom.enable_comp
	if enableComp == False:
		if self.view.custom.currentTabIndex == 0:
			self.view.custom.enable_comp = True
	else:
		if self.view.custom.currentTabIndex == 0:
			self.view.custom.enable_comp = False

After implementing these changes, I have successfully ran multiple tests where the boolean values are set as expected.

Thanks guys!

Edit: both of you contributed to the solution, so I'm going to mark this reply as such, since it contains your implemented feedback.