Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default textarea name for Summernote?

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);
like image 497
Maelish Avatar asked Mar 10 '15 21:03

Maelish


People also ask

How do I add Summernote to textarea?

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.

What is Summernote?

The Summernote Editor is a free & open-source super simple WYSIWYG editor based on Bootstrap & jQuery. It is a JavaScript library that can be useful to build the WYSIWYG editors online.

How do I turn off textarea in Summernote?

You can disable editor by API. $('#summernote'). summernote('disable');


2 Answers

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.

like image 170
Maelish Avatar answered Sep 29 '22 07:09

Maelish


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.

like image 26
Landon B Avatar answered Sep 29 '22 07:09

Landon B