How to Show and Hide Module Subpanel?

Anyone has an idea how to show and hide the subpanel? I have Sub Product module and I added a subpanel in the Product module. Now I want the sub product subpanel will show only if the Product type is Bundled. I tried using custom javascript.

I added this code below in custom/module/AOS_Product/view.detail.php

<?php

require_once 'modules/Documents/views/view.detail.php';

class customAOS_ProductsViewDetail extends ViewDetail{
    public function display()
    {
        parent::display(); // TODO: Change the autogenerated stub

        $javascript = <<<'EOT'
            <script type="text/javascript">
                 const value = document.getElementById('product_type');
                if(value != "Bundled"){
                   
                }
                 $("a[href=#subpanel_aos_products_ptt_subproduct_1]").parents('.panel-default sub_panel').addClass('hidden');
            </script>
        EOT;

        $this->ss->display("custom/modules/AOS_Products/tpls/DetailView.tpl");
        echo $javascript;
    }
}


Hello Everyone, I was able to fixed it. I added a custom tpl at custom/module name/tps/DetailView.tpl

My DetailView.tpl Codes:

<script>
    {literal}
    var productsViewDetail = {
        init: function () {
            productsViewDetail.controlDisplay();
        },
controlDisplay: function () {
let checkbundled = $('[id=part_number]').text();
            $('#whole_subpanel_aos_products_ptt_subproduct_1').hide();
            if( checkbundled.substring(7, 8) == "B" ){
                console.log(checkbundled.substring(7, 8));
                $('#whole_subpanel_aos_products_ptt_subproduct_1').show();
            }
        }
  };
productsViewDetail.init();
    {/literal}
</script>

I added the DetailView.tpl to my view.detail.php:

<?php

require_once 'modules/Documents/views/view.detail.php';

class customAOS_ProductsViewDetail extends ViewDetail{
    public function display()
    {
        parent::display(); // TODO: Change the autogenerated stub
        $this->ss->display("custom/modules/AOS_Products/tpls/DetailView.tpl");
    }
}
1 Like