Imperavi Redactor content not being copied over to hidden textarea

空扰寡人 提交于 2019-12-11 00:22:11

问题


I'm trying to use the Imperavi Redactor control for my rich text editing here:

<div class="control-group">
  <%= f.label :description %>
  <div class="controls">
    <%= f.text_area :description, :class => "richtext" %>
  </div>
</div>

$(document).ready(function(){
    $('.richtext').redactor();
});

The rich text editor appears and works fine, however when I type in content, I can see using the Inspect Element in Google Chrome that the html markup is not being copied over to the hidden text area. See:

<div class="controls">
    //Removed toolbar for brevity.
    <div class="redactor_box">
        <div class="redactor_richtext redactor_editor" contenteditable="true" dir="ltr"><p>asdfjoiasjdf</p><p>dfjiasdfjiasd</p><p>idsfj</p><p>asdffaas</p></div>
    </div>

    <textarea class="richtext" cols="40" id="program_description" name="program[description]" rows="20" style="display: none;"></textarea></div>
</div>

When doing a form POST of this textarea nothing is visible to the server obviously, because the textarea is blank.

Any suggestions on how to have the rich html copied over to the textarea? What am I doing wrong?


回答1:


Try build-in function $().syncCode()

syncCode: function()
{
    var html = this.formatting(this.$editor.html());
    this.$el.val(html);         
}

Or $().setCode()

setCode: function(html)
{
    html = this.preformater(html);

    this.$editor.html(html).focus();

    this.syncCode();
},


来源:https://stackoverflow.com/questions/14636003/imperavi-redactor-content-not-being-copied-over-to-hidden-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!