magentoserializationbackenddepends

Dynamic menu configuration section with conditional inputs on Magento custom module


I've followed this tutorial to create a custom dynamic backend configuration with serialized data, and everything is working as expected. yay

But now I want to take another step and only show some inputs when a specific value is selected in a select box. I know that I can use when doing this with system.xml, but how can I accomplish the same thing via code with dynamics serialized tables?


Solution

  • I ended up doing some kind of Javascript workaround to enable/disable a certain input.

    function togleSelect(element)
    {
        var val = element.value;
        var name = element.name;
        if (val == 0) // select value to be triggered
        {
            name = name.substr(0, name.lastIndexOf("[")) + "[name_of_my_input]";
            var target = document.getElementsByName(name);
            target[0].disabled = false;
        }
        else
        {
            name = name.substr(0, name.lastIndexOf("[")) + "[name_of_my_input]";
            var target = document.getElementsByName(name);
            target[0].disabled = true;
        }
    }
    

    It's not the best solution but it's working.