Real time Word Count Possible

More
1 month 3 weeks ago #159046 by blocka
blocka created the topic: Real time Word Count Possible
I know we have this great solution ( www.limesurvey.org/forum/can-i-do-this-w...acter-counter#155967 ) for real time number of characters left count...

Is there a way to accomplish this for a word count?

Please Log in to join the conversation.

More
1 month 3 weeks ago #159051 by DenisChenu
DenisChenu replied the topic: Real time Word Count Possible
Except with workaround with javascript, i don't see an Expression Manager way :/
stackoverflow.com/questions/14010446/wor...sing-jquery#14010497

EM regexMatch only return boolean, and we don't have any way to "explode" a string with EM.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 month 3 weeks ago #159095 by blocka
blocka replied the topic: How to Create a Real time Word Count for textarea
I was able to accomplish this with the script here:

jsfiddle.net/ezZxf/62/

and Denis Chenu's addScriptToQuestion (which just makes life easier):

extensions.sondages.pro/questions-updati...sily-add-javascript/

1. Put this HTML in your question Help field:
<div class="word-counter">Word Count: <label id="count-label513">0</label>/200</div>

Replace label513 with labelyourquestionID -- this allows you to support more than one textarea per page

(See Image Word1.png)

2. Under Advanced settings, using addScriptToQuestion plugin, add:
var limitWord = 200;
$("#answer268778X29X513").keyup(function () {
    $this = $(this);
    var regex = /\s+/gi;
    var wordcount = jQuery.trim($this.val()).replace(regex, ' ').split(' ').length;
    if (wordcount <= limitWord) {
        chars = $this.val().length;
    } else {
        var text = $(this).val();
        var new_text = text.substr(0, chars);
        $(this).val(new_text);
        wordcount --;
    }
    $("#count-label513").html(wordcount);
});

a) Set limitWord = 200 to your own word limit value
b) Replace answer268778X29X513 with the question ID (use your browser's Element Inspector to find this)
c) Replace label513 with the value you used in Step #1

(See Image Word2.png)

3. Under General Options for your question, in the Validation field, enter this reg-ex:

/^[-\w]+(?:\W+[-\w]+){0,200}\W*$/

Change 200 to your max number of words

(See Image Word3.png)

4. Save and preview your question

(See Image Word4.png)
Attachments:

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!