Page 1 of 1
Hide a child tab problem
Posted: 2021-01-23 05:47
by bruceholt
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
Re: Hide a child tab problem
Posted: 2021-01-23 06:33
by bruceholt
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');
}
})
Re: Hide a child tab problem
Posted: 2021-01-23 11:01
by pbottcher
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.
Re: Hide a child tab problem
Posted: 2021-01-23 19:19
by bruceholt
Hi pböttcher ,
Sorry I'm confused. How do I do that?
Re: Hide a child tab problem
Posted: 2021-01-23 21:40
by pbottcher
Hi,
try
viewtopic.php?t=4095
put your code instead
$j("#TSHDRID-container").select2("disable", true)}
Re: Hide a child tab problem
Posted: 2021-01-23 23:47
by bruceholt
Do you mean?
Code: Select all
$j(function(){
if($j('#sex').val() == 'Female'){
$j("#TSHDRID-container").select2("disable", true)};
}
})
That doesn't work either.

Re: Hide a child tab problem
Posted: 2021-01-24 09:04
by pbottcher
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');
}
})
})
Re: Hide a child tab problem
Posted: 2021-01-25 06:49
by bruceholt
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:
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:
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:
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
Re: Hide a child tab problem
Posted: 2021-01-25 16:04
by pbottcher
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();
}
})
})
Re: Hide a child tab problem
Posted: 2021-01-27 05:21
by bruceholt
Thank you. I'll have a play around with that.