Currently, using the below code in the system.xml
Does anyone have a more efficient way (using only one Field or some other way) to do this?
<?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="vendor" translate="label" type="text" sortOrder="500" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Name of Module</label>
<tab>tabname</tab>
<resource>Namespace_ModuleName::method</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General</label>
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="connection" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Connection</label>
<field id="ssl" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Check</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="comment1" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label> </label>
<comment>If Yes Selected from Field ssl this comment should show.</comment>
<depends>
<field id="vendor/connection/ssl">1</field>
</depends>
</field>
<field id="comment2" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label> </label>
<comment>If No Selected from Field ssl this comment should show.</comment>
<depends>
<field id="vendor/connection/ssl">0</field>
</depends>
</field>
</group>
</section>
</system>
</config>
Using the above code(Separated Fields for each comment) seems to be working as different fields are involved.