I have this JavaScript function that only allows the user to type 42 characters. Can anyone help me, I need every time I get at 42 characters skip a line instead of blocking typing. My problem is in onKeydown
and onKeyup
.
$('.summernote').summernote({
height: 150,
lang: 'pt-BR',
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['insert', ['picture']],
['codeview', ['codeview']]
],
disableDragAndDrop: true,
callbacks:{
onKeydown: function (e) {
var t = e.currentTarget.innerText;
if (t.trim().length >= 42) {
//delete key
if (e.keyCode != 8)
e.preventDefault();
}
},
onKeyup: function (e) {
var t = e.currentTarget.innerText;
$('#maxContentPost').text(42 - t.trim().length);
},
onImageUpload: function(files) {
moveImagem(files[0]);
},
onMediaDelete : function($target, editor, $editable) {
var nome = $target.data('filename');
if(apagaImagem(nome)){
$target.remove();
}
}
}
});