4

i want hide this field. everyone can help me plz! enter image description here

enter image description here

5
  • custom tab or magento core tab ?? – Rk Rathod May 24 '19 at 6:26
  • i want hidden custom tab – NewBie May 24 '19 at 6:28
  • you can delete tab also – Rk Rathod May 24 '19 at 6:28
  • No, i just want hidden it. – NewBie May 24 '19 at 6:29
  • because i have conditions – NewBie May 24 '19 at 6:30
3

You should be able to use the method isComponentVisible()

namespace Custom\Custom\Ui\Component\Form;

use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\ComponentVisibilityInterface;
use Magento\Ui\Component\Form\Fieldset;

/**
 * Class Fieldset
 * @package Custom\Custom\Ui\Component\Form
 */
class CustomFieldset extends Fieldset implements ComponentVisibilityInterface
{
    /**
     * CustomFieldset constructor.
     * @param ContextInterface $context
     * @param array $components
     * @param array $data
     */
    public function __construct(
        ContextInterface $context,
        array $components = [],
        array $data = []
    ) {
        $this->context = $context;

        parent::__construct($context, $components, $data);
    }

    /**
     * @return bool
     */
    public function isComponentVisible(): bool
    {
        $visible = //add logic
        return (bool)$visible;
    }
}

And in your xml you just need to include this class in the fieldset

<fieldset name="custom" sortOrder="30" class="Custom\Custom\Ui\Component\Form\CustomFieldset">
2
  • This is only working in Tab Fieldset not in Normal fieldset. Do you have any idea to show hide Normal Fieldset by using php class? – Siranjeevi K S May 7 '20 at 9:58
  • Working perfect! – Dhaduk Mitesh Jul 25 '20 at 7:23
0

In Tab File You Can Set Tab Visibility Like This :-

public function canShowTab()
{
    return false;

}
public function isHidden()
{
    return true;

}
9
  • i can't call function that – NewBie May 24 '19 at 6:38
  • tab is create using ui ?? – Rk Rathod May 24 '19 at 6:42
  • Can you give me example? i an understand :( – NewBie May 24 '19 at 6:45
  • I don't know how to call function that for my tab! – NewBie May 24 '19 at 6:46
  • find in block any tab folder ??? – Rk Rathod May 24 '19 at 6:46
0

In ui_component

It's just a demo

<fieldset name="design">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="visible" xsi:type="boolean">false</item>
            </item>
        </argument>
    </fieldset>

in your code what you need to hide just put like

<item name="visible" xsi:type="boolean">false</item>
1
  • Yes, i have hidden but just contents still tab not hidden :) – NewBie May 24 '19 at 7:29
0

There are two way to hide the fieldset based on condition.

Step 1: Override prepare method of your fieldset like below.

Your Form.xml

<fieldset name="menu_items" class="Vendor\Module\Ui\Component\Form\CustomFieldset">
    <settings>
        <collapsible>true</collapsible>
        <label>Menu Items</label>
        <visible>false</visible>
    </settings>
    <fieldset name="assign_applicants">
        <settings>
            <label>Menu Items</label>
            <collapsible>true</collapsible>
        </settings>

        <field name="name" sortOrder="30" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">menu</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <dataType>string</dataType>
                <label translate="true">Name</label>
                <dataScope>name</dataScope>
            </settings>
        </field>
    </fieldset>
</fieldset>

Prepare method of your component fieldset class CustomFieldset.php

<?php

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace VendorName\ModuleName\Ui\Component\Form;

use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\ComponentVisibilityInterface;
use Magento\Ui\Component\Form\Fieldset;

/**
 * Class Fieldset
 * @package VendorName\ModuleName\Ui\Component\Form
 */
class CustomFieldset extends Fieldset
{
    /**
     * @var \VendorName\ModuleName\Helper\Data
     */
    protected $helper;

    /**
     * RuleInformationFieldset constructor.
     * @param ContextInterface $context
     * @param array $components
     * @param array $data
     * @param \VendorName\ModuleName\Helper\Data $helper
     */
    public function __construct(
        ContextInterface $context,
        array $components = [],
        array $data = [],
        \VendorName\ModuleName\Helper\Data $helper
    ) {
        parent::__construct($context, $components, $data);
        $this->helper = $helper;
    }

    /**
     * hide or show fieldset based on module enabled or disabled.
     */
    public function prepare()
    {
        $visiable = false;
        $config = $this->getData('config');

        if( $this->helper->isModuleEnable() ) {
            $visiable = true;
        }

        $config['visible'] = $visiable;
        $this->setData('config', $config);
        
        parent::prepare();
    }
}

Step 2: You need to disable the whole fieldset then add the following code in your Data provider class.

/**
 * Get meta function.
 * return mixed
 */
public function getMeta()
{
    $meta = parent::getMeta();

    if($this->helper->isModuleEnable()) {

        $meta['menu_items']['arguments']['data']['config']['visible'] = 1;
    } else{
        $meta['menu_items']['arguments']['data']['config']['visible'] = 0;

    }
    return $meta;
}

Hope it will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.