22892

Imperavi Redactor content not being copied over to hidden textarea

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?

Answer1:

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(); },

Recommend

  • Codeigniter + Redactor (wysiwyg js editor). Image uploading
  • Redactor editor - How to set cursor at the end on focus
  • Creating grails binary plugin results in jar file wich contains all groovy files with comments
  • Java NoClassDefFoundError when running jar containing library jar
  • How can I see Python's __builtins__ source code?
  • How to remove left and right margins from all wrapped rows in flexbox (without nth-child or js)
  • View Paypal shopping cart contents on my site
  • Ability to use Bootstrap 3 grid system to specify width of select element
  • Paypal 'Buy Now' button not letting me dynamically set the price
  • Load Same ACF Map Twice on Same Page
  • How to get real device model in Android?
  • CKeditor stripping font tags instead of converting to span
  • How does ActiveSupport do month sums?
  • Quick Question About Get and Set
  • How can I add div content to a new page in jspdf?
  • Get Currently Active User in Android
  • insert radio value multiple data codeigniter in database to one row?
  • Universal Image Loader reuse images
  • Meteor helpers not available in Angular template
  • Get one-time binding to work for ng-if
  • Is there any way to access browser form field suggestions from JavaScript?
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • ILMerge & Keep Assembly Name
  • Large data - storage and query
  • How can I estimate amount of memory left with calling System.gc()?
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • WOWZA + RTMP + HTML5 Playback?
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Free memory of cv::Mat loaded using FileStorage API
  • Hits per day in Google Big Query
  • -fvisibility=hidden not passed by compiler for Debug builds
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Busy indicator not showing up in wpf window [duplicate]
  • Binding checkboxes to object values in AngularJs
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?