Dynamic character count with jeditable?

(4 posts) (2 voices)
  1. duane, Member

    Hi. I'm trying to get a textarea field to show a live character count (or countdown to the limit) as they type. I've identified the jeditable charcounter plugin and added the two relevant JS files according to https://jeditable.elabftw.net/

    The 'original' (non mydbr instructions) say to add:
    $(".charcounter").editable("save.php", { type : "charcounter", submit : 'OK', tooltip : "Click to edit...", onblur : "ignore", charcounter : { characters : 60 } });

    But I suspect I don't need all of this since part is handled by mydbr (save.php part and perhaps onblur and buttons)

    So I tried adding to the dbr.editable field the options:
    SELECT 'dbr.editable', 'my_field', 'update_function', 'inID=id', 'type=textarea', "options={'rows':20,'cols':70, 'type':'charcounter','charcounter':{'characters':750}}";

    ..but it doesn't work.

    Can you give any suggestions?

  2. duane, Member

    FYI: I'm using dbr.editable in a template (if that matters)

  3. myDBR Team, Key Master

    Duane,
    the character counter plugin introduces a totally separate input type 'charcounter'. Instead, why not just attach the actual character counter functionality (which is separate from the plugin) directly to the already existsing 'textarea' / 'autogrow' input types.

    So what you need is the actual character counter functionality (jquery.charcounter.js) and attach a small function as plugin which will just call the charCounter when the editing starts:

    select 'dbr.head', '<script src="user/js/jquery.charcounter.js"></script>';
    
    select 'dbr.javascript','
    function editable_counter(settings, original){
    $("textarea", this).charCounter(settings.charcounter.characters, settings.charcounter);
    }
    $.editable.types["textarea"].plugin = editable_counter;
    '; select 'dbr.editable', 'textfield', 'sp_DBR_editable_with_counter', 'inID=id', 'type=textarea', "options={'rows':20,'cols':70, charcounter : {characters : 60}}"; select 1 as 'id', 'this is text' as 'textfield'
    ;

    --
    myDBR Team

  4. duane, Member

    I just wanted to follow up to say this works very well - thanks for the help as usual!


Reply

You must log in to post.