# Ignition Tab Container losing custom variable when changing tab

**URL:** <https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304>\
**Category:** Ignition\
**Tags:** ignition81, ignition80, perspective\
**Created:** [December 19, 2023, 11:00am UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304 "2023-12-19T11:00:31Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [December 19, 2023, 11:00am UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/1 "2023-12-19T11:00:31Z")

</div>

Hello,  
I have the [following SSCCE](https://filebin.net/22s96b4m4e6hejky) (Simple Self Contained Code Example) of an undesired behaviour in the Tab container component of ignition:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/4/74f7dd5b74a7efc5681aee6f708f954c94699604.png)

I have a Tab container with two subviews (Tab1 and Tab2), I have created a button "increase" which increases a custom variable each time it is clicked.  
If I increase the counter to 3 in "Tab1" and move to the other tab view "Tab2" and return to "Tab1" the counter is reset to 1.

A tab container should behave imho just like stacked papers on my desk: if I jot down some numbers on a paper and then switch to another paper and then return to the former I don't expect the paper to become clean again!

Of course this is just a simple example however consider the tab component is often used to simplify very complex user interfaces which cannot be dealt within a single view: having each tab reset itself at the change of the tab is a great headache during development.

We think there are also more subtle bugs of the tab component apart from resetting itself (which could itself be dealt with session bindings, or bidirectional parameters but would make the creation of a complex tab view a nightmare for developers), we have examples of the same tab view loading correctly sometimes and some other times not loading correctly as if the custom bindings didn't fire consistently each time.

If you could please address this issue because it is really annoying.

I think the request at [[IGN-2207] Is there a way to stop/intercept a Tab Container tab change?](https://forum.inductiveautomation.com/t/ign-2207-is-there-a-way-to-stop-intercept-a-tab-container-tab-change/45214) is somehow related but didn't want to pollute it with my request.

Thank you

PS: will ignition project attachments be allowed in the future on this forum? I currently have to use third party upload services to share ignition example files.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 19, 2023, 11:08am UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/2 "2023-12-19T11:08:57Z")

</div>

Your SSCCE is missing your embedded views.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/3/53e43eb7c71a0b8dbb213bd5997da620e91548cc.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 19, 2023, 11:16am UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/3 "2023-12-19T11:16:29Z")

</div>

That said, I suspect your custom property is in the embedded view. Consider puting it in either the Tab container or a session property.

---

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [December 19, 2023, 11:25am UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/4 "2023-12-19T11:25:52Z")

</div>

> [@JordanCClark](#):
>
> r SSCCE is missing your embedded views.

I have updated it with the missing views

---

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [December 19, 2023, 11:32am UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/5 "2023-12-19T11:32:31Z")

</div>

> [@r.p](#):
>
> which could itself be dealt with session bindings, or bidirectional parameters but would make the creation of a complex tab view a nightmare for developers),

Hi, as I said, attached is a very simple example which could be dealt with session bindings or bidirectional parameters but would make the creation of a complex tab view a nightmare for developers.  
Apart from that I would see the following happening:

- session would be polluted with variables which belong to embedded views of a tab container of a view, we have hundreds of views it would be an architectural disaster imho to put them in the session.
- session itself has its weird behaviours (it caches user values for some time once a page has opened and persists them even after user logout only to invalidate them after some time).
- moving logic which belongs to a sub view to the parent tab container just so that the tab container can retain the value once the page resets itself on tab change is a nightmare, it would make us probably opt to create two different pages which is not what we want.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 19, 2023, 1:02pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/6 "2023-12-19T13:02:29Z")

</div>

Based on this post, I see what you're saying now. Let's ping @cmallonee and see if he can shed any light for us.

> [@\[IGN-2207\] Is there a way to stop/intercept a Tab Container tab change?](https://forum.inductiveautomation.com/t/ign-2207-is-there-a-way-to-stop-intercept-a-tab-container-tab-change/45214/4):
>
> There isn’t a way to prevent tab changing as of today, but I have two pieces of good news: Nightly 8.1.5 builds should have a code change which keeps Views running even while in tabs which are not active. You should see this change the behavior you’re experiencing such that your fields will retain their values as you switch tabs. I’ve also opened a feature request to allow for “disabling” tabs via a property of each tab. No ETA on when this feature could be implemented. If/when you take the co…

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 19, 2023, 1:10pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/7 "2023-12-19T13:10:59Z")

</div>

Consider storing critical state in a [viewVarMap()](https://www.automation-pros.com/toolkit/doc/scripting.html#viewvarmap) or [pageVarMap()](https://www.automation-pros.com/toolkit/doc/scripting.html#pagevarmap). (Probably want the `pagVarMap()` for this case.) From my Integration Toolkit add-on module.

(These were inspired by a discussion of maintaining page or view state through complex workflows without polluting session variables. And without worrying about long-term memory leaks. And holding the jythonic nature of variables, instead of suffering JSONification everywhere.)

---

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [December 19, 2023, 1:59pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/8 "2023-12-19T13:59:11Z")

</div>

thank you for your input, I would first try avoiding third party modules for such low level things if possible.  
The problem of reloading the tab each time the user switches tab is a problem itself anyway even if variables can be somehow stored inside the tab. Imagine re-executing complex queries each time a user switches tab (almost all complex views involve some kind of query on the DB).  
We also have several problems with the order of execution of custom variables but I'll open a separate thread for that problem.

---

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [December 19, 2023, 2:00pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/9 "2023-12-19T14:00:14Z")

</div>

I opened a separate thread because this topic is more specific (or so I hope). Feel free to edit it if it's not clear enough.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 19, 2023, 3:21pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/10 "2023-12-19T15:21:03Z")

</div>

According to the post, views in tabs are supposed to stay running. I just don't know if that extends down to embedded views within the tabs.

---

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [December 19, 2023, 3:26pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/11 "2023-12-19T15:26:05Z")

</div>

Hi Jordan, according to which post? anyway if the views in tab container stayed running the embedded views of each tab should load once when tab is opened and then stay the same. I suspect some kind of reloading is happening when changing between tabs.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 19, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/12 "2023-12-19T15:29:23Z")

</div>

> [@r.p](#):
>
> according to which post?

EDIT: TL/DR: Yes, I agree. 😉

I linked to the specific post saying that, in v8.1.5, views should stay running if you switch to another tab. I would say that is the behavior you are wanting. Instead, it reloads whatever is in the embedded view, effectively 'resetting' to the original.

---

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [December 19, 2023, 3:31pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/13 "2023-12-19T15:31:54Z")

</div>

thanks I see now, I'll try the nightly **8.1.5** and keep you updated whether it solves this problem. Currently **8.1.33** is experiencing the problem.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 19, 2023, 3:32pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/14 "2023-12-19T15:32:45Z")

</div>

I wouldn't downgrade, let's see if this is a regression.

---

<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:** [December 19, 2023, 4:28pm UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/15 "2023-12-19T16:28:51Z")

</div>

There seems to be some confusion here. In 8.1.5 we [added a boolean property](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+Tab+Container#:~:text=A%20boolean%20runWhileHidden%20property%20can%20be%20added%20to%20an%20element%20that%27s%20set%20to%20an%20object%20data%20type) which exists only under special circumstances, and you must add it yourself. By default, Tabs do not continue running if they are not the active tab. To have a Tab continue to exist - and therefore maintin state - you must modify the tab entry to be an object and supply the `runWhileHidden` property.

**Steps:**

1. Identify the index of the tab which you would like to have its state maintained as you switch between other tabs.
2. Right-click that index and select "Change to", and the "Object". There will be warnings in the Property Editor until we complete our process.
3. Click "Add Object Member" within your new object, and select "Value".
4. Modify the key of the new prop to be `text`, and supply the text you would like displayed for the tab.
5. Hover over your object index, then click the `+` displayed to the right.
6. Select "Value".
7. Set the key of this new prop to be `runWhileHidden`, then set the value to `true`.

There should now be no warnings, and your props should look like this:  
 ![Screenshot 2023-12-19 at 8.27.29 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/a/0a87794997d716b93c1b1405b06032a6ac7e1606.png)

With this setup in place, I was able to increment your counter and navigate between tabs, then go back to the first tab and the count remained incremented.

---

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [December 20, 2023, 10:49am UTC](https://forum.inductiveautomation.com/t/ignition-tab-container-losing-custom-variable-when-changing-tab/83304/16 "2023-12-20T10:49:10Z")

</div>

Thank you, this feature is super useful, it solved several problems we had with some views due to the default behaviour of the tab component.
