What is the default textarea name for Summernote?
Asked Answered
E

4

13

Can someone help me with the default textarea name value for Summernote? The editor looks correct on the page (I can modify text using the interface) but POST isn't working based on my understanding.

I've tried a variety of POST variables but none of them seem correct. Examples are summernote, note-codable and text-area. The last two came from summernote.js. Jquery isn't something that I have much experience with, so please baby-step me.

These are what I am using.

 $('#summernote').summernote({height: 300});
 var sHTML = $('#summernote').code();

and

 <div name="summernote" id="summernote"><?php echo $news_body; ?></div>

I've also tried the lines below separately in an attempt to change the textarea name to content:

var sHTML = $('#summernote').code(); 
$('#summernote').code();
var content = $('textarea[name="content"]').html($('#summernote').code());
$('textarea[name="content"]').html($('#summernote').code());
var sHTML =  $('textarea[name="content"]').html($('#summernote').code());
var textareaValue = $("#content").code();
$("summernote").code(html);
Endoskeleton answered 10/3, 2015 at 21:3 Comment(1)
This turned out to be a very simple fix. The root of the confusion is the documentation that says to use a div. Just use a text-area instead. Although summernote creates a text-area dynamically, do it anyway. It'll work.Endoskeleton
E
46

This turned out to be a very simple fix. The root of the confusion is the documentation that says to use a div. Just use a text-area instead. Although summernote creates a text-area dynamically, do it anyway. It'll work.

Endoskeleton answered 12/9, 2015 at 17:30 Comment(4)
Unfortunately, this causes other problems. For example, &lt;sometext&gt; is automatically converted to <sometext> when you use a textarea. (works correctly when you use a div)Wilkison
jsfiddle --- issue on githubWilkison
@Wilkison I wonder if that is something that's changed with newer versions of Summernote?Endoskeleton
Yes, because of the div it's confusing but I have another confusion or problem which creates a problem for me. I want to show the data on edit form which I receive from jquery table and everything get on edit form but how to show the textarea content on summernote box.Danziger
M
4

I found a working example of using Summernote with php doing a form POST here.

It is a bit convoluted so I will explain what is going on.

First you need to add a textarea that will be the container for the contents of the post. In the example there is one named "content". The textarea doubles as the container for the summernote editor, but you could just as easily use a hidden textarea, and use a div for the summernote container.

To get the data from summernote to the textarea you need to call the .code() function on the summernote element at the time of the POST. The example does this by setting the onsubmit handler to a function (named "postForm" in the example) that finds the summernote element, gets the encoded input, and sets the encoding string as the html of the textarea.

Murage answered 11/3, 2015 at 0:54 Comment(0)
G
0

Try this:

var sHTML = $('.summernote').summernote('code')
Grubstake answered 9/12, 2017 at 17:12 Comment(1)
While this may answer the question, it is better to explain the essential parts of the answer and possibly what was the problem with OPs code.Rubie
W
0

Summernote builds it's own DOM area when it's initialised, even if you use a <textarea> it's markup uses a <div> with the contentEditable attribute for the editable area, which btw, it's class is note-editable.

If you haven't already, I urge you to check https://summernote.org/deep-dive/ page for options for API functions available.

Wolfsbane answered 23/12, 2017 at 3:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.