Question

I try to enable "Field to be enable" when radio button "Enable field" is checked. You can see screenshot field to be enable

UpgradeData.php

            $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'stop_production',
            [
                'group' => 'Product Details',
                'type' => 'int',
                'label' => 'Enabled field',
                'input' => 'boolean',
                'source'   => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
                'default'  => '0',
                'required' => false,
                'sort_order' => 50,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'visible' => true

            ]
        );

        $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'item_replace',  [
            'type'     => 'text',
            'label'    => 'Field to be enable',
            'input'    => 'text',
            'sort_order' => 55,
            'global'  => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'required' => false,
            'group'    => 'Product Details',
            'backend' => 'Wo\StopProduction\Model\Attribute\Backend\ItemReplace'
        ]);

Class ItemReplace.php ( use for disabled field but not working )

{ protected $arrayManager;

public function __construct(
    ArrayManager $arrayManager
) {
    $this->arrayManager = $arrayManager;
}

public function modifyMeta(array $meta)
{
    $meta = $this->customizeItemReplace($meta);

    return $meta;
}

public function modifyData(array $data)
{
    return $data;
}

protected function customizeItemReplace(array $meta)
{
    $weightPath = $this->arrayManager->findPath('item_replace', $meta, null, 'children');

    if ($weightPath) {
        $meta = $this->arrayManager->merge(
            $weightPath . static::META_CONFIG_PATH,
            $meta,
            [
                'dataScope' => 'item_replace',
                'validation' => [
                    'required-entry' => true
                ],
                'additionalClasses' => 'admin__field-small',
                'imports' => [
                    'disabled' => '!${$.provider}:' . self::DATA_SCOPE_PRODUCT
                        . '.stop_production:value'
                ]
            ]
        );
    }
    return $meta;
}

di.xml

    <virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
    <arguments>
        <argument name="modifiers" xsi:type="array">
            <item name="item_replace" xsi:type="array">
                <item name="class" xsi:type="string">Wo\StopProduction\Ui\DataProvider\Product\Form\Modifier\ItemReplace</item>
                <item name="sortOrder" xsi:type="number">10</item>
            </item>
        </argument>
    </arguments>
</virtualType>

First problem: modifier not work for disable field.

Second problem: how can render field enable and required when radio button is enable ?

Many thanks for your help

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top