構成「依存」は、フロントエンドモデルとバックエンドモデルを使用します

magento.stackexchange https://magento.stackexchange.com/questions/15500

質問

構成内の「依存」機能に苦労しています。

通常、追加 <depends> ある構成オプションには、与えられたオプションの値が一致しない限り、非表示になります。

例えば:

<option_one>
    <label>Option 1</label>
    ...
</option_one>
<option_two>
    <label>Option 2</label>
    ...
    <depends><option_one>1</option_one></depends>
</option_two

明らかに私はいくつかのフィールドが欠けていますが、あなたはポイントを得ます。オプション2は、オプション1に値「1」がある場合にのみ表示されます。

ここで、私の問題は、バックエンドとフロントエンドモデルを使用してこれをオプションに適用しようとすると、これは機能しません。

<option_three>
    ...
    <frontend_model>module/adminhtml_form_field_test</frontend_model>
    <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
    ...
    <depends><option_one>1</option_one></depends>
</option_three>

このオプションはオプション1を考慮しません。常に表示されます。

私は何か間違ったことをしていますか、それともこれはバグですか、それとも「設計されているように機能します」ですか?

役に立ちましたか?

解決

使用しない場合 frontend_model 2つのフィールドの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に存在するため、Show/Hideは正常に機能します。

しかし、あなたが使用する場合 frontend_model 2番目のフィールドの値はカスタムブロックによってレンダリングされます 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>
ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top