Adding a tab after it has been removed??

I have a situation where I need to add and remove tabs dependent on the status of the current record in a form. Basically, in my system there are actually two factors that can effect the visibility of tabs.

The first is where the tabs can just be switched on or off, dependent on the users privileges. In this situation the tabs do not need to be added after they have been removed, because they are always either visible, or invisible.

The second is where the tabs can be visible on some records but not on others. Therefore as the user clicks the previous/next buttons etc, those tabs disappear and reappear dependent on the status of the record. As an example of this, I have a contacts form where some contacts are clients, while others aren’t. Basically, the sales tab should only be visible if the contact is a client. Therefore, the sales tab needs to disappear and reappear as a user moves through the records in that form.

I have written some code to deal with this situation, but it doesn’t work properly. Basically the tabs do get removed when I move to a record where they need to be removed. However, when I then move on to another record where it needs to be put back, the tab doesn’t reappear. It seems as though when a tab has been removed, it can’t be put back.

The code I have written to deal with this is listed below:

// Get the selected categories for this contact.  Categories are actually
// check boxes that can be ticked to indicate if a contact is of that type. 
var category_list = categories;

var client_selected = false;

if (category_list != null)
{
	if (category_list.match('Client') != null)
		client_selected = true;
}

// Create the tab index variables.
var attachments_tab_index = 0;
var sales_tab_index = 0;

// Assign values to the tab index variables.
for (var i = 1; i <= elements.lower_tab.getMaxTabIndex(); i++)
{	
	if (elements.lower_tab.getTabNameAt(i) == 'attachments')
		attachments_tab_index = i;
	
	if (elements.lower_tab.getTabNameAt(i) == 'sales')
		sales_tab_index = i;
}

// Add or remove the tabs dependent on settings.
if (contacts_to_superuser.attachments_tab_available == 'yes')
	elements.lower_tab.addTab(attachments_tab_index);
else
	elements.lower_tab.removeTabAt(attachments_tab_index);


if (contacts_to_superuser.sales_tab_available == 'yes' && client_selected)
	elements.lower_tab.addTab(sales_tab_index);
else
	elements.lower_tab.removeTabAt(sales_tab_index);

I have simplified this code considerably. There are actually more categories and more tabs in the real form. All these additional components are set up in the same way as shown above.

Please let me know if there is a better way of doing this. Any info would be greatly appreciated.

Cheers

Craig

craig-c:

elements.lower_tab.addTab(sales_tab_index); 

The addTab() function uses different parameters than removeTabAt().

Thanks for your help on that one. I now have tabs that work properly.

Cheers

Craig