Search code examples
jqueryhtmlsummernote

How to stop typing, when characters is greater than 10?


Follow the code:

Html:

<textarea id="summernote">Test</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) {
    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/114/


Solution

  • try this:
    https://jsfiddle.net/dtgr5q29/116/
    You just need to insert this code:

    $("#summernote").summernote("code", text.substring(0,10));