This happens because you name your field content
. Then the TinyMCE
js looks for the element with id content
to apply the editor. But there is already a content
element on the page and it's a div
.
Adding a prefix to the form elements solves this issue because the element does not have the id content
anymore. It has something_content
.
You can add this prefix with one line of code.
$form->setHtmlIdPrefix('something_');
Doing this, you don't need to alter the form data you pass to $form->addValues
to add your prefix. It will all be done automatically.
The id prefix can be different for each tab if you have multiple tabs.
Suppose you have a textarea:
<textarea name="comment" id="comment" class="input-text"></textarea>
then to add wysiwyg editor to the textarea, you just need to write following code in Javascript file or tag:
require([
'jquery',
'mage/adminhtml/wysiwyg/tiny_mce/setup'
], function(jQuery){
var config = {},
editor;
jQuery.extend(config, {
settings: {
theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,' +
'fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code',
theme_advanced_buttons2: null,
theme_advanced_buttons3: null,
theme_advanced_buttons4: null
}
});
editor = new tinyMceWysiwygSetup(
'comment',
config
);
editor.turnOn();
jQuery('#comment')
.addClass('wysiwyg-editor')
.data(
'wysiwygEditor',
editor
);
});
Best Answer
In html
Script
Hope this helps..