1
Follows the code:
Html:
<textarea id="summernote">Escrever aqui</textarea>
<h5 id="limite_vermelho" style="text-align:right;color:red"></h5>
<h5 id="limite_normal" style="text-align:right"></h5>
JS:
$('#summernote').on('summernote.keyup', function(e) {
debugger;
var text = $(this).next('.note-editor').find('.note-editable').text();
var length = text.length;
var num = 10 - length;
if (length > 10) {
$('#limite_normal').hide();
$('#limite_vermelho').text(10 - length).show();
}
else{
$('#limite_vermelho').hide();
$('#limite_normal').text(10 - length).show();
}
});
Or if you prefer in jsfiddle: https://jsfiddle.net/dtgr5q29/112/
It cannot type more than 10 characters, how can I do this with jquery ?
I have to say that this does not make much sense in a WYSIWYG editor, because if the user, for example, set a text in bold, only the HTML tags occupied 7 characters (
<b></b>). Are you sure this is the best solution to the problem?– Woss
@Andersoncarloswoss, even typing in bold, it does not count. Note on the line:
var text = $(this).next('.note-editor').find('.note-editable').text();, there is way to stop typing the keyboard when it is bigger than 10 ?– Matheus Miranda
So, it would just replace the text by itself when the guy was typing, something like
$(textarea).text(texto), withtextareapointing to the same place from where you are taking the variabletextin your code. The problem is that WISIWYG must have an eventkeyupnext to yours, then: either you use a simple field, or you will need to remove the WISIWYG event and re-experience it. I will try here, I don’t know...– Daniel
I looked at the documentation, I think just use the event
onKeyUphttp://summernote.org/deep-dive/#onkeyup-onkeydown– Daniel
@Daniel, I seem to have found the problem, please check: https://jsfiddle.net/dtgr5q29/117/
– Matheus Miranda
Problem still not fixed, when typing 10 characters in bold, it loses. Looks @Andersoncarloswoss is right.
– Matheus Miranda
There, working... whenever we use other people’s libraries, it’s good to look at their documentation. Some are very fucked.
– Daniel