Magento – Add a class to custom Widget input field

widget

There is a nice little feature when you add form fields to the system configuration where you can use:

<my_field>
    ...
    <validate>some-class</validate>
    ...
</my_field>

This will add a class to your <input> form field which is useful for all sorts of things. Is there a method to do the same when declaring a widget parameter in widget.xml?

Best Answer

I scoured through Magento source, and I did not find where an additional value would be set in widget.xml. While it's a bit annoying, I resorted to using my own <type>.

My widget.xml contains:

<my_param translate="label">
    <required>1</required>
    <visible>1</visible>
    <label>My Label</label>
    <type>module/my_custom_block</type>
</my_param>

The annoying part is that my block class only contains:

class Module_Name_Block_My_Custom_Block extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
{
    public function render(Varien_Data_Form_Element_Abstract $element)
    {
        $element->addClass('my-class');
        $this->_element = $element;
        return $this->toHtml();
    }
}
Related Topic