Reputation: 1232
I need to run some code when the Summernote div on loses its focus. It is not working properly. Please help.
$('#summernote').on('summernote.blur', function(){
alert('Editable area loses focus');
});
Upvotes: 0
Views: 1642
Reputation: 705
Summernote use it's default classes, in that case I think this way will help also,
$(document).find('.summernote').on('summernote.blur', function(){
alert('Editable area loses focus');
});
$(document).ready(function() {
var editor = $('#summernote');
editor.summernote({
height: ($(window).height() - 250),
focus: false,
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough']],
['fontsize', ['fontsize']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['view', ['fullscreen', 'codeview']],
],
oninit: function() {
// Add "open" - "save" buttons
var noteBtn = '<button id="makeSnote" type="button" class="btn btn-default btn-sm btn-small" title="Identify a music note" data-event="something" tabindex="-1"><i class="fa fa-music"></i></button>';
var fileGroup = '<div class="note-file btn-group">' + noteBtn + '</div>';
$(fileGroup).appendTo($('.note-toolbar'));
// Button tooltips
$('#makeSnote').tooltip({
container: 'body',
placement: 'bottom'
});
// Button events
$('#makeSnote').click(function(event) {
var highlight = window.getSelection(),
spn = document.createElement('span'),
range = highlight.getRangeAt(0)
spn.innerHTML = highlight;
spn.className = 'snote';
spn.style.color = 'blue';
range.deleteContents();
range.insertNode(spn);
});
},
});
$(document).find('.summernote').on('summernote.blur', function() {
alert('Editable area loses focus');
});
});
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote.min.js"></script>
<div style="width: 100%; height: 95px;text-align: center;padding-top: 10px;">
Outer Area
</div>
<textarea class='summernote' id='summernote' rows='10'></textarea>
Upvotes: 1