Sunday 15 May 2011

javascript - Save formatted text to database and retrieve it back 'as is' like a formatted string -


I'm embedding in [Twitter] http://www.tinymce.com/ Twitter Bootstrap, so that user input Can be formatted text that I can continue in the Postgraduate database

The problem I am facing is that I am getting plain text on submitting the form. Does anyone help me get formatted text in a string, which I can continue and resonate on the HTML page.

This is my code [note: it uses ham]

 % html {: lang = & gt; "N"}% head% meta {: charset = & gt; "Utf-8"}% link {: href = & gt; "//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" ,: rel = & gt; "Stylesheet"}% script {: src = & gt; "//tinymce.cachefly.net/4.0/tinymce.min.js"}: javascript tinymce.init ({selector: 'texture_form'}); % Body Container% Legend Post a new job. Good% form # signup.form-horizontal {: action = & gt; "Submit" ,: method = & gt; "Post"}% Legend. Control-group% label.control-label title. Control. Input-prepaid% span.add-on% i.icon-user% input # title.input-xxlarge {: name = & gt; "Title" ,: Placeholder = & gt; "Title" ,: type = & gt; "Text"} / .control-group% label.control-label Description formatted. Control. Input-prepaid - #% span.add-on - #% i.icon-user% textarea_format # message.input-xlarge.span6 {: name = & gt; "Message_formatted" ,: rows = & gt; "10"}. Control group% label.control-label.controls% button.btn.btn-success {: type = & gt; "Submit"} Submit   

It seems that I can use tinyMCE.get ('Content ID'). GetContent () But I'm not sure how?

New to very Java-scripts. Can someone post a specific code change and post some explanation

thanks

Actually, the easiest way to do this is to click a field in your form and a click event handler on the submit button.

So, create a hidden input on your appearance with the name "Message-formatted" (since I think your corresponding field in your model is called message_formatted), and the name of your textera And to change it, because it will no longer be important.

Using jQuery:

  $ ('# signup input [type =' (function (e) {$ ('input [name = message_formatted]') Val (tinyMCE.get ('content id'). GetContent ());});   

In the case of adding JavaScript, it is up to you. This is the best in the JavaScript directory. (It is not clear whether or not you are using Rail and Asset pipeline). If you just want to add Javascript inline inside this HAM page, then con to the bottom of your page Tant_for: javascript do

  content_for: javascript // Enter javascript from above here    

No comments:

Post a Comment