iuux / adrx-quicknotes

Quick Notes functionality for Indiana University AdRx (Advising Records) system.
MIT License
0 stars 0 forks source link

Create textarea character countdown #11

Open basham opened 9 years ago

basham commented 9 years ago

Something like:

320 / 500 remaining characters

basham commented 9 years ago

CKEditor has no build-in character limit, like the maxlength HTML attribute. Would have to use an existing plugin or create something custom.

Have to consider how markup relates to character count. If not included, which is more sensible, then the HTML has to be stripped out in order to ensure a proper plain text count (maximum of 1000 characters, as determined by Success Criteria). Then you're betting that there's no combination of markup that CKEditor would create that would push the character count beyond the database limit (4000 characters).

basham commented 9 years ago

Plugins:

basham commented 9 years ago

http://stackoverflow.com/a/27720326

window.onload = function() {
    CKEDITOR.instances.mytext.on( 'key', function() {
        var str = CKEDITOR.instances.mytext.getData();
        if (str.length > 50) {
            CKEDITOR.instances.mytext.setData(str.substring(0, 50));
        }
    } );
};