2
protected function _prepareLayout()
        {
            $return = parent::_prepareLayout();
            if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
                $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
            }
            return $return;
        }

I have a custom module with an admin grid. I try to use TinyMCE but it gives an error in console as described in this title. I use the following code

$fieldset->addField("preface", "editor", array(
                        "label" => Mage::helper("knowledgebase")->__("Preface"),
                        'style' => 'width:98%; height:300px;',
                        'wysiwyg' => true,
                        'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
                        "name" => "preface",
                        ));

protected function _prepareLayout()
        {
            $return = parent::_prepareLayout();
            if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
                $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
            }
            return $return;
        }
Sukeshini
  • 9,945
  • 18
  • 71
  • 126
matthijs
  • 143
  • 2
  • 5

2 Answers2

6

You are probably missing the JS files required for the editor. Check out this blogpost about integrating the editor on custom admin forms.

Especially the first part:

Add necessary js and css files in app/design/frontend/default/default/layout/editor.xml

<default>
            <reference name="head">
            <action method="setCanLoadExtJs"><flag>1</flag></action>
            <action method="setCanLoadTinyMce"><flag>1</flag></action>
            <action method="addJs"><script>mage/adminhtml/variables.js</script></action>
            <action method="addJs"><script>mage/adminhtml/wysiwyg/widget.js</script></action>
            <action method="addJs"><script>lib/flex.js</script></action>
            <action method="addJs"><script>lib/FABridge.js</script></action>
            <action method="addJs"><script>mage/adminhtml/flexuploader.js</script></action>
            <action method="addJs"><script>mage/adminhtml/browser.js</script></action>
            <action method="addJs"><script>prototype/window.js</script></action>
            <action method="addJs"><script>prototype/prototype.js</script></action>
            <action method="addItem"><type>js_css</type><name>prototype/windows/themes/default.css</name></action>
            <action method="addItem"><type>js_css</type><name>prototype/windows/themes/magento.css</name></action>
            </reference>
    </default>
Sander Mangel
  • 37,528
  • 5
  • 80
  • 148
0

You can also utilize the pre-made handle for the wysiwyg editor.

If the editor javascript is only necessary for the admin module you are creating as well as the ones that already use it then you can create an xml document (titled anything with the extension xml) in app/design/adminhtml/default/default/layout/editor.xml and add the following xml.

<your_modules_handle_here>
     <update handle="editor" />
</your_modules_handle_here>