I have a problem getting CKEditor value with Jquery. When I open the console, I have Cannot read property 'getData' of undefined
.
I looked at the code rendered and ckEditor seem to be not rendered when the script part is there. When I remove the script part, it's rendered well in HTML. Whether the script is there or not, CKEditor is on the page and working, I only see the difference in HTML.
My code:
{{ form_start(form, {'id': 'formCorrection'~reponse.id}) }}
{{ form_widget(form.commentaire, {'id': 'commentaire'~reponse.id}) }}
{{ form_row(form.submit) }}
{{ form_end(form) }}
<script>
var idCommentaire = 'commentaire{{ reponse.id }}';
var commentaire = CKEDITOR.instances[idCommentaire].getData();
$("#formCorrection{{ reponse.id }}").submit(function() {
$.ajax({
type: "POST",
url: "{{ path('paces_colle_correctioncolleqr_sauvegardercorrectionpassage') }}",
data: {commentaire: commentaire}
})
});
</script>
With script part :
<textarea id="commentaire1148472" name="paces_colle_correctioncolleqr_correctionreponseqr[commentaire]" required="required" class="ckeditor"></textarea>
Without the script part :
<textarea id="commentaire1148472" name="paces_colle_correctioncolleqr_correctionreponseqr[commentaire]" class="ckeditor" style="visibility: hidden; display: none;"></textarea>
<div id="cke_commentaire1148472" class="cke_1 cke cke_reset cke_chrome cke_editor_commentaire1148472 cke_ltr cke_browser_webkit" dir="ltr" lang="fr" role="application" aria-labelledby="cke_commentaire1148472_arialbl">['ckEditor stuff']</div>