1

I have one drop down with fixed set of values lets call 1 to 5. when i select any number that many number of textboxes should be visible in the admin system configuration in magento 2.

for example. if i select 3 from drop down then i want to show 3 text boxes just below the dropdown. if i select 1 from drop down then one text box should be shown.

please help me how can i achieve this in Magento 2

0

Try following way:

Suppose your field like


<field id="test" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
    <source_model>VendorName\ModuleName\Model\Config\Source\Dropdown</source_model>
</field>

And your dropdown has following value


namespace VendorName\ModuleName\Model\Config\Source;

class Dropdown implements \Magento\Framework\Option\ArrayInterface
{
    public function toOptionArray()
    {
        $options = [];
        $options[] = ['value' => '1', 'label' => 'One'];
        $options[] = ['value' => '2', 'label' => 'Two'];
        $options[] = ['value' => '3', 'label' => 'Three'];
        return $options;
    }
}

Now added following code where you want to depends


<depends>
    <field id="test">2</field>
</depends>

So for example:


<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Title</label>
    <depends>
        <field id="test">2</field>
    </depends>
</field>

In above example, title field will be visible if test value is 2.

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.