Imperavi Redactor content not being copied over to

2019-07-17 04:12发布

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条回答
劫难
2楼-- · 2019-07-17 04:31

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();
},
查看更多
登录 后发表回答