galetahub / ckeditor

Ckeditor 4.x integration gem for rails
https://ckeditor.com/ckeditor-4/
MIT License
2.22k stars 881 forks source link

What is the correct way to copy/paste an innerHTML by javascript to a textarea input, managed by CKEditor ? #896

Closed Bertrand-Bichat closed 3 years ago

Bertrand-Bichat commented 4 years ago

I have succeeded to implement CKEditor in an input textarea of a rails new/edit simple_form_for. It works well. But I have some javascript code which copy an innerHTML somewhere to paste it in the input textarea managed by CKEditor, and this not working. I don't find the right "id" or "class" in this input to use with a querySelector in order to paste my innerHTML. I have already tried with .content-input , #substep_content , .substep_content and .cke_editable, but it doesn't work. Someone can help me, please ? Here is the form :

<%= simple_form_for(@substep) do |f| %>
    <%= f.input :content, label_html: { class: "content-label" }, input_html: { rows: 15, class: "content-input", ckeditor: { toolbar: 'Full' } }, as: :ckeditor %>
<% end %>

When I open "page source code" :

<div class="form-group ckeditor optional substep_content">
 <label class="ckeditor optional content-label" for="substep_content">Contenu</label>
 <textarea rows="15" class="ckeditor optional content-input" name="substep[content]" id="substep_content"></textarea>
 <script>
<img width="531" alt="CKEditor" src="https://user-images.githubusercontent.com/58553969/87330638-29019a00-c539-11ea-9f35-0f3fe613c21c.png">

 //<![CDATA[
 (function() {
            if (typeof CKEDITOR != 'undefined') {
              if (CKEDITOR.instances['substep_content']) { CKEDITOR.instances['substep_content'].destroy(); }
              CKEDITOR.replace('substep_content', {"toolbar":"Full","customConfig":"/assets/ckeditor/config-dff8e9963191c33e28d6d4ccec8784c5b317df36f5ae95a4f171ca46bd9f1df2.js"});
            }
          })();
 //]]>
 </script>
</div>

Here the : Image of inspector / examine the item

CKEditor
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.