Page 1 of 1

tabs.get("tablename") not working

Posted: 2022-06-28 11:05
by kerelov
Hi,
I'm trying to add a link to a children tab but I cant get the child tab I need.
I'm getting all tabs and I can activate the tab I need with tabs.activate("tablename");
The problem comes when I'm trying to operate a single tab with tabs.get("tablename");. This function returns null in the console.
Here is my code:

Code: Select all

var dv = new AppGiniDetailView();
var tabs = dv.getChildrenTabs();
tabs.activate("slaughterhouse_exported"); //working
var tab = tabs.get("slaughterhouse_exported"); 
console.log(tab); // returns null
tab.addBadge(123); //cant get properties of null

Re: tabs.get("tablename") not working

Posted: 2022-06-28 11:22
by kerelov
Appgini 22.14
Appgini Helper Library Version 2022.06.27

Re: tabs.get("tablename") not working

Posted: 2022-06-30 04:33
by jsetzer
(1) Constructor for dv

Please note that the constructor you are using is deprecated:

Please use:

Code: Select all

var dv = AppGiniHelper.dv;
Please do not use:

Code: Select all

var dv = new AppGiniDetailView(); // DO NOT USE THIS
In the past that constructor sometimes lead to unexpected behaviour in cases in which programmers used copy&paste sample code and created multiple instances of AppGiniDetailView for example in header-extras.php and in TABLENAME-tv.js and in TABLENAME-dv.js. To prevent consequential errors, the singleton AppGiniHelper.dv was introduced.

---

(2) addBadge() function

I have found a mistake in my changelog: The addBadge(number)-function refers to custom tabs, not children tabs. I'm sorry for my mistake and I have corrected it in code and website.

The following code works for (self-created) custom tabs:

Code: Select all

// file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
var layout = dv.createLayout(); 
layout.add(1, ["#Order", "id", "number" /* more fields */ ]);
layout.add(2, ["#Customer", "customer_id" /* more fields*/ ]);

var tabOrder = dv.addTab("tabOrder", "Order", "shopping-cart", layout);
// ...more tabs

tabOrder.addBadge(123);

chrome_DYcaJIxbml.png
chrome_DYcaJIxbml.png (18.09 KiB) Viewed 3786 times

---


(3) functions for children tabs

Lazy loaded elements (like children tabs) will not be available when the script has loaded nor on document-ready. Changes to them can be applied after the element has been (lazy) loaded. There is a function dv.ready(fn) in AppGini Helper Javascript Library which will wait for all lazy loading events and will then execute your code.

Example for changing the tab-caption of a child-tab:

Code: Select all

// file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
dv.ready(function() {
    var tab_notes = dv.getChildrenTabs().get("notes");
    tab_notes.label("Changed Tab Caption");
});
chrome_wCVTuzfsZ4.png
chrome_wCVTuzfsZ4.png (6.54 KiB) Viewed 3786 times

Once again, I'm sorry for my mistake in changelog!

Re: tabs.get("tablename") not working

Posted: 2022-06-30 08:57
by kerelov
Thanks for clearing out what is possible with child tabs.
I still cant get to work any tab function:

Code: Select all

var dv = AppGiniHelper.dv;
dv.ready(function() {
	var tabs = dv.getChildrenTabs();
    tabs.activate("slaughterhouse_exported"); //working perfectly 
	var tab_exp = tabs.get("slaughterhouse_exported"); //not found
    tab_exp.label("Changed Tab Caption"); //properties of null
});
error in console

Code: Select all

AppGiniHelper | child tab for table/lookup not found: slaughterhouse_exported
_0x1a5c27.<computed> @ AppGiniHelper.min.js:7
_0x3468a3.get @ AppGiniHelper.min.js:7
(anonymous) @ slaughterhouse_export-dv.js:8
(anonymous) @ AppGiniHelper.min.js:7
i @ jquery-3.5.1.min.js:2
dispatch @ jquery-3.5.1.min.js:2
v.handle @ jquery-3.5.1.min.js:2
trigger @ jquery-3.5.1.min.js:2
l @ jquery-3.5.1.min.js:2
(anonymous) @ jquery-3.5.1.min.js:2
load (async)
send @ jquery-3.5.1.min.js:2
ajax @ jquery-3.5.1.min.js:2
S.<computed> @ jquery-3.5.1.min.js:2
_0x342004.<computed> @ AppGiniHelper.min.js:7
_0x1a5c27 @ AppGiniHelper.min.js:7
_0x1a5c27.<computed> @ AppGiniHelper.min.js:7
get @ AppGiniHelper.min.js:7
get @ AppGiniHelper.min.js:7
(anonymous) @ slaughterhouse_export-dv.js:4
if I change some names in the code it works for one time and after refresh throws again an error in the console that the table is not found.

Re: tabs.get("tablename") not working

Posted: 2022-06-30 09:05
by kerelov
So the situation is exactly as follows. In 10 times refreshing the page 5-6 times it shows the old caption and 4-5 times the new one. There is no order sometimes it changes every time sometimes it stays for a few refreshes. Removing tabs.activate doses not improve the final result.

Re: tabs.get("tablename") not working

Posted: 2022-06-30 09:22
by kerelov
Adding just a 100ms timeout before initializing the tab var solves the problem.

Code: Select all

var dv = AppGiniHelper.dv;
dv.ready(function() {
	var tabs = dv.getChildrenTabs();
	tabs.activate("slaughterhouse_export_docs");
	setTimeout(
		function() 
		{
			var tab_exp = tabs.get("slaughterhouse_export_docs"); 
			tab_exp.label("Changed Tab Caption");
		}, 100
	);
	
});
So I don't know ...