Magento Widget – Add WYSIWYG Editor to Custom Widget

widgetwysiwyg

I am attempting to add a WYSIWYG editor to a field within a custom widget. I'm actually able to get the WYSIWYG editor to appear as displayed in the screenshot below:

My problem is that the data from the WYSIWYG editor is not populating the hidden textarea field, so the field contents are blank. (If I click the "Show/Hide" editor so that it is rendering plain HTML and then click "Insert Widget", the field's contents are copied over as expected.)

Am I missing core functionality of the WYSIWYG editor that is preventing the translation from the editor to the textarea field or is there way that I can insert some JS when the WYSIWYG field is added to copy over the editor's contents when the element loses focus?

Here are the relevant portions of my widgets.xml (omitting opening/closing widget tag)

<brands_detailedslide type="city_brands/widget_detailedslide">
    <name>Detailed Slide</name>
    <description type="desc">Creates Markup for a Detailed Slide</description>
    <parameters>
        <slide_content>
            <label>Slide Content</label>
            <visible>1</visible>
            <required>1</required>
            <type>city_brands/widget_slide_wysiwyg</type>
        </slide_content>
    </parameters>
</brands_detailedslide>

Note that the type points to City_Brands_Block_Widget_Slide_Wysiwyg, which contains:

class City_Brands_Block_Widget_Slide_Wysiwyg extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
{
    public function render(Varien_Data_Form_Element_Abstract $element)
    {

        $editor = new Varien_Data_Form_Element_Editor($element->getData());

        //Prevent foreach error that occurs without this
        $editor->getConfig()->setPlugins(array());

        $editor->setId($element->getId());
        $editor->setForm($element->getForm());
        $editor->setWysiwyg(true);
        $editor->setForceLoad(true);

        return parent::render($editor);
    }
}

enter image description here

Best Answer

The problem is that the information is only copied across when you select the button Show/Hide editor and not as you type.

You could build in some JavaScript that copied the content on blur or submitting the form.

Related Topic