Я его подключил, загрузил, все работает пока у меня одно textarea.
Если их несколько, то работает только последняя. А в остальных(при отправке формы) textarea остается пустым => ошибка валидации. Внешне все грузиться корректно.
Инициализирую все textarea по отдельности таким образом: (каждая editor_selector уникальна)
- Код: Выделить всё
<script type="text/javascript">
function initTinyMCE(areaID) {
console.log(areaID);
tinyMCE.init({
mode : "textareas",
theme : "advanced",
editor_selector : areaID,
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true
});
}
$( "#addChapter" ).click(function() {
var lastChapterID = Number($('.lastChapterID').text());
var newChapterID = lastChapterID+1;
$('.lastChapterID').text(newChapterID);
var htmlChapterForm = '<div class="chapters chapter-'+newChapterID+'"><a href="#remove-new-form" class="remove_chapter">Удалить</a><div class="control-group"><label for="chapterTitle[]" class="control-label">Заголовок раздела</label><input id="chapterTitle[]" type="text" name="chapterTitle[]" value="" required="required" class="chapterTitleInput ccm-input-text"></div><div class="control-group"><label for="chapterContent[]" class="control-label">Текст раздела</label><textarea id="chapterContent[]" name="chapterContent[]" class="advancedEditor-'+newChapterID+' ccm-advanced-editor ccm-input-textarea"></textarea></div></div>';
$(".all-chapters").append(htmlChapterForm);
initAllTextArea();
});
$(document).on("click", "a.remove_chapter", function() {
if (confirm("Вы действительно хотите удалить этот раздел?")){
$(this).parent().remove();
}
});
function initAllTextArea() {
$(".ccm-advanced-editor").each(function() {
var areaClass = $(this).attr('class');
var areaClass = areaClass.split(' ');
initTinyMCE(areaClass[0]);
});
}
$(document).ready(function(){
initAllTextArea();
});
</script>
Вид самой формы (одного раздела)
- Код: Выделить всё
<div class="chapters chapter-<?php echo $key; ?>">
<a href="#remove-<?php echo $key; ?>" class="remove_chapter remove_chapter-<?php echo $key; ?>">Удалить</a>
<div class="control-group">
<?php
echo $form->label('chapterTitle[]', "Заголовок раздела");
echo $form->text('chapterTitle[]', $chapter['title'], array('required' => 'required', 'class' => 'chapterTitleInput'));
?>
</div>
<div class="control-group">
<?php
echo $form->label('chapterContent[]', "Текст раздела");
$class = 'advancedEditor-'.$key;
echo $form->textarea('chapterContent[]', $chapter['text'], array('class' => $class.' ccm-advanced-editor'));
?>
</div>
</div>