Skip to content

<depends> field doesn't work in system.xml for "radios" fields #9360

Closed
@WaPoNe

Description

@WaPoNe

In system.xml file a field can depend on another field value; it will be shown or not depending from previous field choice.
It works fine if the field depends on a "select" field but if you try to use a "radios" field dependency the mechanism doesn't work and the field will always be shown.

Preconditions

  1. Magento 2.1.5

Steps to reproduce

app/code/vendorName/moduleName/etc/adminhtml/system.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="wapone" translate="label" sortOrder="1000">
            <label>WaPoNe</label>
        </tab>
        <section id="stickers" translate="label" type="text"
                 sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Stickers</label>
            <tab>wapone</tab>
            <resource>WaPoNe_Stickers::config_stickers</resource>
            <group id="stickers_page" translate="label" type="text"
                   sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Stickers page settings</label>
                <field id="discount_calculation" translate="label" type="radios"
                       sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Discount Calculation</label>
                    <source_model>WaPoNe\Stickers\Model\Config\Backend\DiscountCalculationType</source_model>
                </field>
                <field id="discount_category" translate="label" type="text"
                       sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Discount Product Category</label>
                    <depends>
                        <field id="stickers/stickers_page/discount_calculation">automatic</field>
                    </depends>
                </field>
            </group>
        </section>
    </system>
</config>

app/code/vendorName/moduleName/Model/Config/Backend/DiscountCalculationType.php:

<?php

namespace WaPoNe\Stickers\Model\Config\Backend;

use Magento\Framework\Option\ArrayInterface;

class DiscountCalculationType implements ArrayInterface
{
    public function toOptionArray()
    {
        $calculationType = array();

        $calculationType[] = [
            'value' => 'manual',
            'label' => __('Manual')
        ];
        $calculationType[] = [
            'value' => 'automatic',
            'label' => __('Automatic')
        ];

        return $calculationType;
    }
}

Expected result

  1. discount_calculation value = 'automatic' => discount_category is shown
  2. discount_calculation value = 'manual' => discount_category is not shown

Actual result

  1. discount_category is always shown so is not working

If I declare discount_calculation field as "select" type, all works fine

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions