Create a Dependent Field in Admin Configuration
Do you want to display fields in admin configuration depending on other fields values? Let's see how you can easily do that!
In the system.xml below we have defined two fields, a select field and a text field. The select field has option values Yes / No. Selecting the option value Yes, the text field is shown.
So the field option <depends> is what you all need to create fields depending on other fields values and you have to define the depending field's id and the value. The value is 1 for Yes and 0 for No.
If you want make this field depending on more than one value, the you have to defined a separator and the values for the option depend. Like in the example below, where we display the text field on both selected values of the select field.
If the depending field belongs on another group, the when we have to define the whole path of the depening field as id. Like on the example below that the text field of the group post25b, depends on the value of the select field of the group blog25.
Feel free to share this post and ask your questions in the comments below.
That was the last Magento 2 post for 2017. We hope you enjoyed all of them.
More Magento 2 post are coming next year.
Wish you all Happy New Year!
Till next time!