views:

2961

answers:

6

DOJO seems to have some quirks here. I specifically need to have the TabContainer hidden when the page loads, but then become visible after the user clicks a button. The first thing I tried is setting style.display = "none" to start, and then setting style.display = "block" on the click event. Unfortunately, this only partially works- the page will render an invisible box in the right location/dimensions, but not render the actual contents. The box's contents only get rendered when triggered by something else (for example, going to a different FF tab or suspending/resuming firebug will make the box render).

If the style.display property is set to be visible on page load, everything works fine. You can toggle the display property and it shows or hides the tabcontainer properly. But if it's set to "none" on page load, it screws up.

I tried a workaround of setting the style.display property to "" in the HTML but then immediately setting it to "none" in the Javascript, but it still fails- the change occurs too soon and it needs to happen after the tabcontainer renders (which can take a second or two).

Some stripped sample code:

HTML:
<div id="tabContainer" dojoType="dijit.layout.TabContainer" style="width:500px; height:100px;display:none;">
</div>

and then the Javascript to show the tab on a user click:

function initTabs()  
{  
var tabContainer = dojo.byId('tabContainer');  
tabContainer.style.display = 'block';  
}

How can I dynamically show/hide a TabContainer without having it start in the shown state?

A: 

you should do

dijit.byId("tabContainer").domNode.style.display = 'block'

or perhaps

dijit.byId("tabContainer").domNode.style.visibility = 'hidden';

is even better

Marijn
the first option doesn't work, either. The second option, modified to be what I assume you intended ('visible' and not 'hidden') works a little bit better, but still not right. Using the visibility property makes the TabContainer hide and show properly, but it still takes up space on the page while hidden (an invisible box).
Well you could change the position to absolute. But that makes it kind of an ugly hack.
Marijn
display = 'none'
Wahnfrieden
A: 

Well, I did not solve this problem, but I came up with a workaround...Creating the TabContainer on the click event, instead of creating it hidden on page load and then showing it on the click event.

HTML:

<div id="tabContainer">     
</div>

JS:

var tabContainer = new dijit.layout.TabContainer({id:"tabContainer", style:"width:500px;height:200px;"}, dojo.byId('tabContainer'));  
//add tabs
tabContainer.startup();
A: 

After you set display:block do this:

dijit.byId('tabContainer').resize();

dijit.layout widgets often don't lay themselves out properly if they are display:none (and sometimes even when visibility:hidden). You have to fiddle around in Firebug till you figure out what works!

Michael B
A: 

There is solution for this. If you want to show TabContainer calll:

dijit.byId("tabContainer").domNode.style.display = 'block';
dijit.byId("tabContainer").resize();

and use 'none' if you want to hide TabContainer.

This works for me, but that is truth, it is not obvious :)

Lukasz R.
A: 

the first thing (setting style.display = "none") is right. In place of

...then setting style.display = "block"

you should just call .set_visible JS method of the ajax TabContainer when "...user clicks a button"

like

$find('<%= Tabs.ClientID %>').set_visible(true);

A: 

Wow, you guys helped me solve a problem at work that had been moritifying me for over 2 weeks. I didn't know you could invoke dijit.byId("id").resize() w/o arguments.

Now the HTML elements I was trying to hide don't leave the blank space they take up when not hidden.

Thanks, and how can I repay you?

Jose