I thought I was cool and had figured something out here. but alas. I’m humbled.
The goal is to create a next tab and previous tab script that can handle tabs that can be conditionally rendered away.Generally, the expected syntax for ‘next tab’ would run something like this:
tabset.tabs(“option”, “active”, tabset.tabs(“option”, “active”) +1). But that causes trouble when a tab is conditionally rendered away.
Here’s a page to see what’s happening:
<skuidpage unsavedchangeswarning="" showsidebar="false" showheader="true"> <models>
<model id="User" limit="0" query="false" createrowifnonefound="true" sobject="User" doclone="" type="">
<fields>
<field id="IsActive"/>
<field id="UserPreferencesActivityRemindersPopup"/>
<field id="ReceivesAdminInfoEmails"/>
<field id="ForecastEnabled"/>
<field id="UserPermissionsMobileUser"/>
<field id="UserPreferencesApexPagesDeveloperMode"/>
<field id="UserPermissionsCallCenterAutoLogin"/>
<field id="EmailPreferencesAutoBcc"/>
<field id="EmailPreferencesAutoBccStayInTouch"/>
<field id="UserPermissionsChatterAnswersUser"/>
<field id="UserPreferencesContentEmailAsAndWhen"/>
<field id="UserPreferencesContentNoEmail"/>
</fields>
<conditions/>
<actions/>
</model>
</models>
<components>
<basicfieldeditor showheader="true" showsavecancel="false" model="User" buttonposition="" mode="edit" layout="">
<columns>
<column width="33.3%">
<sections>
<section title="Section A" collapsible="no" showheader="false">
<fields>
<field id="IsActive" valuehalign="" type="">
<label>A</label>
</field>
<field id="UserPreferencesActivityRemindersPopup" valuehalign="" type="">
<label>B</label>
</field>
<field id="ReceivesAdminInfoEmails" valuehalign="" type="">
<label>C</label>
</field>
<field id="ForecastEnabled" valuehalign="" type="">
<label>D</label>
</field>
</fields>
</section>
</sections>
</column>
<column width="33.3%">
<sections>
<section title="Section B" collapsible="no" showheader="false">
<fields>
<field id="UserPermissionsMobileUser" valuehalign="" type="">
<label>E</label>
</field>
<field id="UserPreferencesApexPagesDeveloperMode" valuehalign="" type="">
<label>F</label>
</field>
<field id="UserPermissionsCallCenterAutoLogin" valuehalign="" type="">
<label>G</label>
</field>
<field id="EmailPreferencesAutoBcc" valuehalign="" type="">
<label>H</label>
</field>
</fields>
</section>
</sections>
</column>
<column width="33.3%">
<sections>
<section title="Section C" collapsible="no" showheader="false">
<fields>
<field id="EmailPreferencesAutoBccStayInTouch" valuehalign="" type="">
<label>I</label>
</field>
<field id="UserPermissionsChatterAnswersUser" valuehalign="" type="">
<label>J</label>
</field>
<field id="UserPreferencesContentEmailAsAndWhen" valuehalign="" type="">
<label>K</label>
</field>
<field id="UserPreferencesContentNoEmail" valuehalign="" type="">
<label>L</label>
</field>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
<tabset rememberlastusertab="false" defertabrendering="false" renderas="">
<tabs>
<tab name="A">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="IsActive" value="true"/>
</renderconditions>
</tab>
<tab name="B" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="UserPreferencesActivityRemindersPopup" value="true"/>
</renderconditions>
</tab>
<tab name="C" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="ReceivesAdminInfoEmails" value="true"/>
</renderconditions>
</tab>
<tab name="D" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="ForecastEnabled" value="true"/>
</renderconditions>
</tab>
<tab name="E" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="UserPermissionsMobileUser" value="true"/>
</renderconditions>
</tab>
<tab name="F" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="UserPreferencesApexPagesDeveloperMode" value="true"/>
</renderconditions>
</tab>
<tab name="G" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="UserPermissionsCallCenterAutoLogin" value="true"/>
</renderconditions>
</tab>
<tab name="H" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="EmailPreferencesAutoBcc" value="true"/>
</renderconditions>
</tab>
<tab name="I" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="EmailPreferencesAutoBccStayInTouch" value="true"/>
</renderconditions>
</tab>
<tab name="J" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="UserPermissionsChatterAnswersUser" value="true"/>
</renderconditions>
</tab>
<tab name="K" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="UserPreferencesContentEmailAsAndWhen" value="true"/>
</renderconditions>
</tab>
<tab name="L" loadlazypanels="true">
<components/>
<renderconditions logictype="and">
<rendercondition type="fieldvalue" operator="=" enclosevalueinquotes="false" fieldmodel="User" sourcetype="fieldvalue" nosourcerowbehavior="deactivate" field="UserPreferencesContentNoEmail" value="true"/>
</renderconditions>
</tab>
</tabs>
</tabset>
</components>
<resources>
<labels/>
<javascript/>
<css/>
</resources>
</skuidpage>
To reproduce the issue:
Check C, D, E, F, G, I, and J.
Open Console
//define these variables:
var $ = skuid.$;
var tabset = $('body').find('.ui-tabs').first();
var initialTabNumberArray = r],
secondTabNumberArray = ],
thirdTabNumberArray = ],
fourthTabNumerArray = ],
fifthTabNumberArray = ];
- Get the tab number values from jQuery ui tabs widget
//Click on each tab and run
initialTabNumberArray.push(tabset.tabs("option", "active"));
As a result, initialTabNumberArray should be
r0, 1, 2, 3, 4, 5, 6], as expected.
- Uncheck E, G, and I (leaving only C, D, F, and J)
//Click on each tab and run
secondTabNumberArray.push(tabset.tabs("option", "active"));
As a result, secondTabNumberArray is
u0, 1, 3, 6].
This is no problem, as long as it’s consistent.
We should be able to do something like
var tabpanels = $(tabset).children(‘.ui-tabs-panel’), and loop through the tabpanels after the active tab until we find one that has the attribute data-rendered=“true”, and pass that value back into tabToActivate in tabset.tabs(“option”, “active”, tabToActivate).
- Now check A E H K L, so your current visible tabs are A C D E F H J K L
//Click on each tab and run
thirdTabNumberArray.push(tabset.tabs("option", "active"));
thirdTabNumberArray returns <0, 1, 2, 3, 4, 5, 6, 7, 8]
Tabs have reset to have 0-8 sequentially.
Check I, uncheck J K E so your current visible tabs are A C D F H I L, and populate fourthTabNumberArray, which returns p0, 1, 2, 4, 5, 6, 9]
Uncheck A and L so your current visible tabs are C D F H I J, and populate fifthTabNumberArray, which returns p0, 1, 2, 3, 4, 5].
In the third and fifth tab number arrays, i can no longer use the tabpanels jQuery method described above to check if the next tab is rendered, because as soon as the ui-tabs widget resets the indexes of the tabs, I have no way to reliably connect those indexes to those of the tabpanels array created with $(tabset).children(‘.ui-tabs-panel’). I either need a reliable way to connect the indexes, or some other way to determine if the ‘next panel’ is rendered. Ideally, i could force the ui-tabs widget to reset the indexes of the tabs every time there was a change in rendering, so I could just run tabset.tabs(“option”, “active”, tabset.tabs(“option”, “active”) +1) and not have to check for visiblity.
Thoughts?