4 ms·
You actually don't have to use a <div>, you can use a textarea or any form element. However, the catch is that if you just grab the form elements on submit you
by jeffmould 11y ago
You actually don't have to use a <div>, you can use a textarea or any form element. However, the catch is that if you just grab the form elements on submit you have to keep the html elements. There are a couple options here:
1. The simplest way is to put an onsubmit in your form element that handles this.
Example:
<script>
var postForm = function() {
var content = $('textarea[name="content"]').html($('#summernote').code());
}
</script>
<form action="#" method="POST" onsubmit="return postForm()">
....
</form>
2. The other way is to use an onchange for the summernote element. Every time it changes it updates the textarea with the appropriate code.
Example:
$(document).ready(function() {
$('#summernote').summernote({
onKeyup: function(e) {
$("#summernoteContent").val($("#summernote").code());
},
height: 300,
});
});
where #summernoteContent is your textarea.
EDIT TO ADD:
Now with that said, my biggest issue is that the documentation is not clear on many things. Especially the API. Summernote has a pretty good API available, but it is poorly documented and is constantly evolving.