How to configure TinyMCE in nette 24/04/2015

Usefull links - Official site TinyMCE - Configuration Attach TinyMCE to textarea By class (recommended) $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.

Usefull links - Official site TinyMCE - Configuration

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()');
Following is not tested, but hypothetically should work.

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()');
}