Skip to content

Use system value on depends field with required value #14373

@thomas-kl1

Description

@thomas-kl1

I didn't found any related issues in your backlog, if it actually already exists, my apologies.

## Unhanded event when the "Use system value" is triggered in the store configuration admin interface.

Preconditions

  1. Magento 2.4-develop
  2. Custom configuration as following (simplified) in 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>
        <section id="system">
            <group id="my_custom_settings" translate="label" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>My Custom Settings</label>
                <field id="custom_field_disable" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Disable Button</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="custom_field_value" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Select Field</label>
                    <source_model>Vendor\Module\Model\Config\Source\MyOptions</source_model><!-- return empty array or first value is empty -->
                    <can_be_empty>0</can_be_empty>
                    <validate>required-entry</validate>
                    <depends>
                        <field id="custom_field_disable">0</field>
                    </depends>
                </field>
            </group>
        </section>
    </system>
</config>
  1. Default configuration values in the config.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <system>
            <my_custom_settings>
                <custom_field_disable>1</custom_field_disable>
            </my_custom_settings>
        </system>
    </default>
</config>

Steps to reproduce

  1. Add above content in the system.xml and config.xml of a custom module
  2. Clear the cache
  3. Go to store > config > Advanced > System > My Custom Settings
  4. Uncheck "Use system value" of the "Disable Button" field
  5. Check value "Yes"
  6. "Select Field" field appear, (do not select any value)
  7. Check "Use system value" of the "Disable Button" field

Expected result

  1. The depends fields should disappears
  2. We are able to save the config

Actual result

  1. Depends fields are still visibles
  2. Can't save because the "Select Field" is required
    #14373

Workaround

  1. Select manually the value of the first field

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Framework/AppEvent: mm20inIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: ready for devReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions