How to configure TinyMCE in Nette

Usefull links

Attach TinyMCE to textarea

$form->addTextArea('text', 'Text')
    ->setAttribute('class', 'mceEditor');
tinyMCE.init({
    mode: "specific_textareas",
    editor_selector: "mceEditor",
    ...
});

By ID

$form->addTextArea('text', 'Text')
    ->setHtmlId('mceEditor');
tinyMCE.init({
    mode: "exact",
    elements: "mceEditor",
    ...
});

Configuring validation

To enable validation in textarea with TinyMCe it is important to save written text to textarea before Nette validation.

If a form contains only one button (or if all buttons runs validation) you can attach text saving on onSubmit of the form.

$form->getElementPrototype()->onsubmit('tinyMCE.triggerSave()');

If one of the buttons doesn't run validation (i.e., “Back”, set up by setValidationScope), validation is attached to onClick of those buttons, which run the validation.

foreach ($form->getComponents(TRUE, 'SubmitButton') as $button) {
    if (!$button->getValidationScope()) continue;
    $button->getControlPrototype()->onclick('tinyMCE.triggerSave()');
}