Hide a child tab problem

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Hide a child tab problem

Post by bruceholt » 2021-01-23 05:47

I have viewed Ahmed's YouTube video - https://www.youtube.com/watch?v=1cERqwXxpzI titled "How to hide a child tab if a lookup field meets a certain condition". I have tried to implement the code in the tablename-dv.js hooks file but it keeps failing. I think (obviously) that I have completely got the syntax all wrong.

Code: Select all

$j(function(){
	(function)(){
if($j('#sex').val() == 'Female'){
$j('#tab_animals-sire').parents('li').addClass('hidden')
}
$j('#panel_animals-sire').addClass('hidden');	
})
Thanks Bruce

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Hide a child tab problem

Post by bruceholt » 2021-01-23 06:33

I also tried:

Code: Select all

$j(function(){
     
	 if($j('#sex').val() == 'Female'){
                $j('#tab_animals-sire').parents('li').addClass('hidden')
		$j('#panel_animals-sire').addClass('hidden');
            }
        })

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Hide a child tab problem

Post by pbottcher » 2021-01-23 11:01

Hi,

you need to make sure that the child table is already available. Usually the child table is loaded later, so your code will not find the table an hence will not hide it.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Hide a child tab problem

Post by bruceholt » 2021-01-23 19:19

Hi pböttcher ,

Sorry I'm confused. How do I do that?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Hide a child tab problem

Post by pbottcher » 2021-01-23 21:40

Hi,
try

viewtopic.php?t=4095

put your code instead
$j("#TSHDRID-container").select2("disable", true)}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Hide a child tab problem

Post by bruceholt » 2021-01-23 23:47

Do you mean?

Code: Select all

$j(function(){
     
	 if($j('#sex').val() == 'Female'){
				$j("#TSHDRID-container").select2("disable", true)};
            }
        })
That doesn't work either. :(

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Hide a child tab problem

Post by pbottcher » 2021-01-24 09:04

No, something like

Code: Select all

function wait_for(data,callback,time=100) {
	if($j(data).length != 0) {
		callback();
		return;
	}
	else {
		setTimeout(function() {
			wait_for(data,callback, time);
		}, time);
	}
}
$j(function() {		
	wait_for("#tab_animals-sire", function() {
		if($j('#sex').val() == 'Female'){
	                $j('#tab_animals-sire').parents('li').addClass('hidden')
			$j('#panel_animals-sire').addClass('hidden');
	         }
	 })
})
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Hide a child tab problem

Post by bruceholt » 2021-01-25 06:49

Thanks pböttcher,

I managed to get one of the tabs hiding but the other one won't.

This is what it looks like normally:

Image

When I placed this code in:

Code: Select all

function wait_for(data,callback,time=100) {
	if($j(data).length != 0) {
		callback();
		return;
	}
	else {
		setTimeout(function() {
			wait_for(data,callback, time);
		}, time);
	}
}
$j(function() {		
	wait_for("#tab_animals-dam", function() {
		if($j('#sex').val() == 'Male'){
	                $j('#tab_animals-dam').parents('li').addClass('hidden')
			$j('#panel_animals-dam').addClass('hidden');
	         }
	 })
})
I get this which is correct:

Image

When I reverse it so that the dam tab is hidden.
Changed code:

Code: Select all

function wait_for(data,callback,time=100) {
	if($j(data).length != 0) {
		callback();
		return;
	}
	else {
		setTimeout(function() {
			wait_for(data,callback, time);
		}, time);
	}
}
$j(function() {		
	wait_for("#tab_animals-sire", function() {
		if($j('#sex').val() == 'Female'){
	                $j('#tab_animals-sire').parents('li').addClass('hidden')
			$j('#panel_animals-sire').addClass('hidden');
	         }
	 })
})
I get this:

Image

What I am trying to do is place both codes, so that depending on what sex the sire or dam is, the irrrevelant tab should be hodden.

Sorry to be a pain!

Regards, Bruce

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Hide a child tab problem

Post by pbottcher » 2021-01-25 16:04

Hi,

if that is the case you could try:

Code: Select all

function wait_for(data,callback,time=100) {
	if($j(data).length == 2) {
		callback();
		return;
	}
	else {
		setTimeout(function() {
			wait_for(data,callback, time);
		}, time);
	}
}
$j(function() {		
	wait_for("#tab_animals-sire, #tab_animals-dam", function() {
		if($j('#sex').val() == 'Female'){
	                $j('li.child-table-animals_sire').hide();
	         }
	        else {
	                $j('li.child-table-animals_dam').hide();
	        }
	 })
})
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Hide a child tab problem

Post by bruceholt » 2021-01-27 05:21

Thank you. I'll have a play around with that.

Post Reply