如果您不frontend_model
将html用于两个字段,则将如下所示
<tr id="row_you_dependency_field_id">
<td class="label"><label for="you_dependency_field_id">Dependency Field</label></td>
<td class="value">
<select id="you_dependency_field_id" name="groups[general][fields][you_dependency_field_id][value]" class=" select">
<option value="1">Yes</option>
<option value="0" selected="selected">No</option>
</select>
</td>
</tr>
<tr id="row_your_dependent_field_id">
<td class="label">
<label for="your_dependent_field_id">Dependent Field</label>
</td>
<td class="value">
<select id="your_dependent_field_id" name="groups[general][fields][your_dependent_field_id][value]" class=" select">
<option value="1">Yes</option>
<option value="0" selected="selected">No</option>
</select>
</td>
</tr>
显示/隐藏依赖字段的javascript看起来像这样
new FormElementDependenceController({"your_dependent_field_id":{"you_dependency_field id":"1"}});
显示/隐藏将正常工作,因为两个ID都存在于html中。
但是,如果您使用frontend_model
第二个字段的值,则该字段由您的自定义块呈现,module/adminhtml_form_field_test
并且不包含相关字段的ID,而JavaScript只是不知道要隐藏什么。
<tr id="row_you_dependency_field_id">
<td class="label"><label for="you_dependency_field_id">Dependency Field</label></td>
<td class="value">
<select id="you_dependency_field_id" name="groups[general][fields][you_dependency_field_id][value]" class=" select">
<option value="1">Yes</option>
<option value="0" selected="selected">No</option>
</select>
</td>
</tr>
<tr id="row_your_dependent_field_id">
<td class="label">
<label for="your_dependent_field_id">Dependent Field</label>
</td>
<td class="value">
...
//The output of your frontend_model
...
</td>
</tr>
因此,转到的_toHtml()方法module/adminhtml_form_field_test
并将输出包装到其中div
并为其指定ID
$fieldId = $this->getElement()->getId();
//your html
<div id="field id here">
//your frontend_model html
</div>