2

I have one yes/no select field in a widget.xml

If "yes" was selected then category select field should be visible.

But category select field always visible instead. That's wrong.

Here is my widget.xml:

<select_category_type translate="label description">
    <label>Select categories</label>
    <visible>1</visible>
    <type>select</type>
    <values>
        <item0 translate="label">
            <value>0</value>
            <label>No</label>
        </item0>
        <item1 translate="label">
            <value>1</value>
            <label>Yes</label>
        </item1>
    </values>
    <sort_order>25</sort_order>
</select_category_type>

<selected_category translate="label">
    <visible>1</visible>
    <required>1</required>
    <label>Select categories</label>
    <type>label</type>
    <helper_block>
        <type>av_widget_product_featured/catalog_chooser</type>
        <data>
            <button translate="open">
                 <open>Select Categories...</open>
            </button>
            <use_massaction>1</use_massaction>
        </data>
    </helper_block>
    <depends>
        <select_category_type>
            <value>1</value>
        </select_category_type>
    </depends>
    <sort_order>30</sort_order>
</selected_category>
3

The problem is that you cannot use depends on widget items that are of type chooser :(

In the file js/mage/adminhtml/form.js it processes the changes on widgets in the function trackChange. Here is loads the hidden field that is used to store the value of the item as a reference and the using up it works up the dom to find the td that is should show or hide.

The problem with the chooser items is that there is no hidden input field that matches the id format that magento is looking for.

You will see the JS error Uncaught TypeError: Cannot read property 'up' of null.

To get part of the depends working you can look into how the html of the chooser is built in the file Mage_Widget_Block_Adminhtml_Widget_Chooser. By simply adding a hidden field with the id $element->getId() to the returned string of the function _toHtml the field itself with hide/show but the button for choosing will not as this is part of a different row in the table. Here you would have to update the javascript to deal with the structure. Luckly the $chooserId that is used to build the button appears to be derived from the element id and so this should be fairly simply to find via javascript.

| improve this answer | |
  • You're right. But is there some solutions to fix it? – Anthony Apr 28 '14 at 12:03
  • @Anthony sadly I have not been able to find one yet. – David Manners Apr 28 '14 at 12:10
  • @Anthony I have updated with some more findings regarding when and where the html is built. – David Manners Apr 29 '14 at 6:49
  • This still happends in Magento 2 right? – Gianni Di Falco Jul 4 '16 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.