In this post I am going to explain how to add dependant field in admin system configuration in magento 2.
In order to create a field dependant on single value, use the below code:
1 2 3 | <depends> <field id="parent_field_id">1</field> </depends> |
And to create a field dependant on two or more values, use the below code:
1 2 3 | <depends> <field id="parent_field_id">1,2,3</field> </depends> |
Here is the example in which, if parent field’s (Enabled) value “1” then “Title” field will appear.
1 2 3 4 5 6 7 8 9 10 | <field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enabled</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> <field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Title</label> <depends> <field id="enabled">1</field> </depends> </field> |
Thats it. Enjoy Magento 2!!
Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!
Leave a Reply