Reputation: 3635
Having a simple set up for summernote.
<div id="summernote">data-here</div>
$('#summernote').summernote({
height: 200, // set editor height
focus: true,
callbacks // any callbacks didn't worked, onChange, onBlur etc..(any tip on how to add proper callbacks here)
});
I tried to make jquery code to catch on change event of my summernote, like:
$('#summernote').on("summernote.change", function (e) {
# Problem here when deleting (keyboard backspace, calls twice)
-some code here-
}
My problem with the summernote.change
is that when deleting text/content using keybord's backspace, the callback (on change) triggers twice instead.
Thus my inside function runs twice too.
Any idea on this guys, Thanks in advance.
Upvotes: 0
Views: 4943
Reputation: 20039
I tried to recreate the issue. But it works fine for me.
$(document).ready(function() {
$('#summernote').summernote({
height: 200, // set editor height
focus: true,
callbacks: {
onInit: function() {
console.log('Summernote is launched');
},
onChange: function(contents, $editable) {
console.log('onChange:', contents, $editable);
}
}
});
$('#summernote').on('summernote.change', function(we, contents, $editable) {
console.log('summernote.change', contents, $editable);
});
});
<!-- include libraries(jQuery, bootstrap) -->
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<!-- include summernote css/js -->
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.js"></script>
<div id="summernote">data-here</div>
Note: You should use either of the events onChange
in callbacks or summernote.change
not both.
Upvotes: 3
Reputation: 1054
As I know, it’s a known issue (https://github.com/summernote/summernote/issues/2888), but nobody tried to fix it.
So, I use it like this :
var mySec = 100;
var myEvent;
$('#summernote').on("summernote.change", function (e) {
clearTimeout(myEvent);
myEvent = setTimeout(function(){
console.log(e) // do something!
}, mySec);
});
I hope this will help you :)
Upvotes: 1