# View Startup, Enable or disable components

**URL:** <https://forum.inductiveautomation.com/t/view-startup-enable-or-disable-components/76741>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 22, 2023, 1:44am UTC](https://forum.inductiveautomation.com/t/view-startup-enable-or-disable-components/76741 "2023-07-22T01:44:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [July 22, 2023, 1:44am UTC](https://forum.inductiveautomation.com/t/view-startup-enable-or-disable-components/76741/1 "2023-07-22T01:44:01Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 22, 2023, 10:58am UTC](https://forum.inductiveautomation.com/t/view-startup-enable-or-disable-components/76741/2 "2023-07-22T10:58:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 23, 2023, 12:01am UTC](https://forum.inductiveautomation.com/t/view-startup-enable-or-disable-components/76741/3 "2023-07-23T00:01:48Z")

</div>

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

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

```

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

> [@mdemaris](#):
>
> Is the popup view actually firing the start up event every time the popup opens?

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.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [July 24, 2023, 9:02pm UTC](https://forum.inductiveautomation.com/t/view-startup-enable-or-disable-components/76741/4 "2023-07-24T21:02:32Z")

</div>

> [@Transistor](#):
>
> Do the same with `custom.enable_comp`. Move it out to `view.custom` and then you can create a binding to that.

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:

```auto
    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:

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

```

@cmallonee  
Instead of this:

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

```

I went with this:

```auto
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:

```auto
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.
