1
I have this Javascript function that only allows the user to type 42 characters. Someone can help me, I need every time I reach 42 characters to 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();
}
}
}
});
I found a way, it’s kind of "Ambi" but it will serve you, I will post
– Leandro RR