Multiples Ckeditor on the same page

0

I'm creating a system in which the user can place as many textarea as he wants, the system is ready. The code to do this is this:

function addPergunta(){
    pergunta++;
    var corpo = "<div id='pergunta-" + pergunta + "'><hr><h3>Pergunta " + pergunta + "</h3><textarea id='textEditor' class='textarea-pergunta' placeholder='Escreva a pergunta...'' name='pergunta-" + pergunta + "' required></textarea><div id='itens-" + pergunta + "'><div id='item-" + pergunta + "-1' style='display: inline'>1. <input type='text' class='item-pergunta' name='item-" + pergunta  + "-1' placeholder='Escreva a alternativa para essa pergunta' required></div></div><button type='button' class='add-item' onclick='addItem(" + pergunta + ")' data-toggle='tooltip' title='Adicionar ítem à questão' id='addItem-" + pergunta + "'><span class='fa fa-plus'></span></button><button type='button' class='add-item' onclick='removerItem(" + pergunta + ")' data-toggle='tooltip' title='Remover um ítem!' id='removerItem-1'><span class='fa fa-close'></span></button><input type='text' class='resposta' placeholder='Insira a resposta certa para essa questão' name='resposta-" + pergunta+ "' required></div>";
    var areaPerguntas = document.getElementById('perguntas');
    areaPerguntas.insertAdjacentHTML('beforeend', corpo);
    itens[pergunta] = 1;
    return;
}

What matters is that I create this textarea with normal javascript and tals. But I wanted to put this textarea as a text editor, I've been using CKeditor for a while and I really like it, but what happens is that I can not load it when I do this DOM, it loads only once when I load the page . If someone has some method of loading it every time it adds a new textarea.

NOTE: It does not have the id corresponding to Ckeditor in this code, which is why I took it until I solved this problem. I also tried loading the CKeditor into this function, but it does not load.

Thank you in advance!

    
asked by anonymous 27.05.2016 / 03:06

1 answer

1

You need to give a unique ID to each textarea. For example 'textEditor-pergunta-' + pergunta to follow the logic you have.

You can do this like this:

 CKEDITOR.replace('textEditor-pergunta-' + pergunta);

At the end of your function.

Example: link

    
27.05.2016 / 03:24