Needed to use <br>
tag in the summernote editor instead of <p>
while user clicks on the Enter button, so here is my code:
var $this = $(this),
box = $('textarea.CommentsFields');
box.summernote({
height: 100,
focus: true,
toolbar: [
[ 'all', [ 'bold', 'strikethrough', 'ul', 'ol', 'link' ] ],
[ 'sided', [ 'fullscreen' ] ]
],
callbacks: {
onEnter: function(){
box.summernote('insertNode', document.createTextNode("<br>"));
console.log('uiwdbvuwecbweuiuinsjk');
}
}
});
I wrote a custom callback of the onEnter event, when the user hit the return button it raises a callback, and write the <br>
tag which is not what I am looking for.
I read their documentation but can not understand how to stop the default action of the enter button and write <br>
tag instead of wrapping the element in <p>
tag.
Any idea? Thanks
You can customize it with popover. air option. $('#summernote'). summernote({ popover: { air: [ ['color', ['color']], ['font', ['bold', 'underline', 'clear']] ] } });
html(text). text(); . Because if you the content of summernote contain some plain text and you don't wrap the whole content inside an HTML tag(like div) then, jQuery will through an error saying it was not expected.
You can disable editor by API. $('#summernote'). summernote('disable'); If you want to enable editor again, call API with enable.
This code worked for me:
$("#summernote").on("summernote.enter", function(we, e) {
$(this).summernote("pasteHTML", "<br><br>");
e.preventDefault();
});
This interceps the Enter press event and changes its default behaviour, inserting a <br>
instead of a new paragraph.
If you don't want to change or fix the summernote library itself, you can use the shortcut keys
for adding a line break.
Shift + Enter
for giving a line break.Enter
for changing a paragraph, as summernote
add a div
/p
to start a new line when you press Enter
.Hope this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With