1
The idea is not to allow typing more than 10 characters. The Crtl + V is failing.
Example:
- Type 9 characters in
- And then use Crtl + V (fault), it is at this point is allowed to type more than 10 characters.
Follows JS code:
$(document).ready(function () {
$('#summernote').summernote({
toolbar: [
['style', ['bold', 'italic', 'underline', 'clear']]
],
callbacks: {
onKeydown: function (e) {
var t = e.currentTarget.innerText;
if (t.trim().length >= 10) {
//delete key
if (e.keyCode != 8)
e.preventDefault();
}
},
onKeyup: function (e) {
var t = e.currentTarget.innerText;
$('#maxContentPost').text(10 - t.trim().length);
},
onPaste: function (e) {
var t = e.currentTarget.innerText;
var bufferText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text');
e.preventDefault();
var all = t + bufferText;
document.execCommand('insertText', false, all.trim().substring(0, 10));
$('#maxContentPost').text(10 - t.length);
}
}
});
});
Or if you prefer Jsfiddle: https://jsfiddle.net/sz1fj325/3/
Some solution ?
Wouldn’t it be better to create a unique event that fires after a timeout and clears the field?
– Guilherme Nascimento