1

I need to insert two wysiwyg fields with tinymce in my backend module in the same form.

It's working when I insert only one with this code in the edit tab form:

$fieldset->addField('mother', 'editor', array(
    'name'      => 'mother',
    'label'     => Mage::helper('cms')->__('Mother content'),
    'title'     => Mage::helper('cms')->__('Mother content'),
    'style'     => 'height:12em;width:30em',
    'required'  => true,
    'wisiwyg'   => false,
    'config'      => Mage::getSingleton('cms/wysiwyg_config')->getConfig()
));

and this one in the editAction in the controllers

$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
    $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}

But when I try to insert a second one, chrome doesn't load tinymce and crashes (unable to close the tab in chrome, I need to use windows task management to cancel the chrome process). Maybe a JS conflict? I can't even access the console in chrome...

[EDIT after comment] And below the maybe problematic code for the second wysiwyg field

$fieldset->addField('content', 'editor', array(
    'name'      => 'content',
    'label'     => Mage::helper('cms')->__('Main content'),
    'title'     => Mage::helper('cms')->__('Main content'),
    //'style'     => 'height:36em;width:30em',
    'required'  => true,
    'wisiwyg'   => true,
    'config'      => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
));
3
  • can you show the code you use to add the second editor? It may have something to do with the id and/or name of the field.
    – Marius
    Jun 9, 2017 at 6:07
  • Hi, i just edited my question with the informations you asked fore, let me please know if you've an idea Jun 9, 2017 at 6:12
  • Exactly what I suspected. I'm in the middle of my answer now. Come back in 5 minutes. :)
    – Marius
    Jun 9, 2017 at 6:13

1 Answer 1

1

I assume that the $fieldset variable comes from something like this:

$fieldset = $form->addFieldset(....)

where $form is $form = new Varien_Data_Form();
I mean, this is the standard way of doing it. If it's not standard, it's the one mostly used.

Try adding this right after initializing the $form variable.

$form->setHtmlIdPrefix('something_here_');

Now, why this might work.
The id of the element added in the form is generated based on the first parameter you pass to the method addField.
So your code will generate a text area with the id content in this case.
And there is already an element with the id content in the DOM. it's a div that wraps almost all the page content.
And the editor is trying to position itself on that div instead of the textarea and fails miserably.

Adding the line $form->setHtmlIdPrefix('something_here_'); will make all elements in the form to have the id something_here_some_id instead of some_id. And you avoid the conflicts.

In conclusion, the problem is not that you add 2 editors in the page. Is the name of the second one. You can easily test this, but removing the first editor and leaving just the second one with the name content. The page will still crash.

1
  • this is working : perfect! Thanks a lot ! (for the record i i took this code from the mage cms page form declaration wich also use content as a key, that's why i didn't suspect a key problem) Jun 9, 2017 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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