- Posts: 409
- Thank you received: 34
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Real time Word Count Possible
- blocka
- Topic Author
- Offline
- Platinum Member
Less
More
6 years 6 months ago #159046
by blocka
Real time Word Count Possible was created by blocka
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?
Is there a way to accomplish this for a word count?
The topic has been locked.
- DenisChenu
- Away
- LimeSurvey Community Team
Less
More
- Posts: 13620
- Thank you received: 2488
6 years 6 months ago #159051
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on 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.
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 , plugin development .
I don't answer to private message.
The topic has been locked.
- blocka
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 409
- Thank you received: 34
6 years 6 months ago #159095
by blocka
Replied by blocka on 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:
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:
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)
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:
Code:
<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:
Code:
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)
The following user(s) said Thank You: cmnxyz
The topic has been locked.
- jltrussart11
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 2
6 years 1 month ago #165173
by jltrussart11
Replied by jltrussart11 on topic How to Create a Real time Word Count for textarea
Thanks for this wonderful workaround.
Could the number of words be dermined by the user on a previous question?
Could the number of words be dermined by the user on a previous question?
The topic has been locked.
- jltrussart11
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 2
6 years 1 month ago #165176
by jltrussart11
Replied by jltrussart11 on topic How to Create a Real time Word Count for textarea
Could we use regex to do it?
The topic has been locked.
- cmnxyz
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
4 years 10 months ago #185916
by cmnxyz
Replied by cmnxyz on topic How to Create a Real time Word Count for textarea
Hey there! since i dont have admin rights to install external plugins i have to use the workaround within the source code of the question. I followed the upper instruction and I put my questionID and the questionlabelID accordingly. However, when I enter text, its displaying: "Please check the format of your answer." Any clue what causes this problem? I'm using LimeSurvey 3.14. Kind regards
Attachments:
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12903
- Thank you received: 3967
4 years 10 months ago - 4 years 10 months ago #185919
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic How to Create a Real time Word Count for textarea
Hi, you have to surround blocka's script by
$(document).on('ready pjax:scriptcomplete',function(){
.....
});
This is the advantage of Denis' plugin - you don't need it; but without plugin, you have to use the full javascript.
Version 3.17.4+190529
But the format error seems to be something different. I never saw something like this when I tested. And I was not able to reproduce it.
So, you have to send us your *.lss with only this question.
Anyway, you should hide the tip. This tip "please, check the format..." is confusing, because it refers to the regular expression in your validation.
All the best
Joffm
$(document).on('ready pjax:scriptcomplete',function(){
.....
});
This is the advantage of Denis' plugin - you don't need it; but without plugin, you have to use the full javascript.
Version 3.17.4+190529
But the format error seems to be something different. I never saw something like this when I tested. And I was not able to reproduce it.
So, you have to send us your *.lss with only this question.
Anyway, you should hide the tip. This tip "please, check the format..." is confusing, because it refers to the regular expression in your validation.
All the best
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 10 months ago by Joffm.
The topic has been locked.