Magento – How to show custom admin form tabs conditionally

adminformcustommagento-1tabs

I need to show two tabs in admin custom form in which 2nd tab will only visible after I save the contents of first tab. Any one can tell me the way to do this.

This is what I have –

protected function _beforeToHtml()
{
    $product_content = $this->getLayout()->createBlock('bulkpricechanger/adminhtml_bulkpricechanger_edit_tab_product', 'adminform_products.grid')->toHtml();
    $serialize_block = $this->getLayout()->createBlock('adminhtml/widget_grid_serializer');
    $serialize_block->initSerializerBlock('adminform_products.grid', 'getSelectedProducts', 'products', 'selected_products');
    //$serialize_block->addColumnInputName('position');
    $product_content .= $serialize_block->toHtml();
    $this->addTab('associated_products', array(
    'label' => Mage::helper('bulkpricechanger')->__('Select Products'),
    'title' => Mage::helper('bulkpricechanger')->__('Select Products'),
    'content' => $product_content
    ));

    // $this->addTab("form_section", array(
    // "label" => Mage::helper("bulkpricechanger")->__("Update Price Settings"),
    // "title" => Mage::helper("bulkpricechanger")->__("pdate Price Settings"),
    // "content" => $this->getLayout()->createBlock("bulkpricechanger/adminhtml_bulkpricechanger_edit_tab_form")->toHtml(),
    // ));

    return parent::_beforeToHtml();
}

This is what i have in Tab.php I need to show the "form_action" tab to be shown only after products are selected from "associated_produts" tab.

Best Answer

On your tab you can make the function canShowTab. This will return a boolean value if the tab can be shown or not. In this function you can perform a check to see if your conditions are matched. A good example of this is the block Mage_Adminhtml_Block_Customer_Edit_Tab_View which only shows after the customer has been saved.

public function canShowTab()
{
    if (Mage::registry('current_customer')->getId()) {
        return true;
    }
    return false;
}