Skip to main content

Hi,

 

I need to set the Text Area to accept a Word count as follows:

Minimum Words: 1000

Maximum Words: 2000

 

Is there a way to set this up on a Text Area?

 

If so, can the word count also be displayed alongside the TextArea so the user knows how many words they have written so far?

 

Thanks

Hello,


 


The current max property of the control is 1000 max characters, however you may be able to use a "Control Action" to change this runtime.


 http://help.k2.com/onlinehelp/k2smartforms/userguide/current/default.htm#Control_Properties_Actions.html 


 


 


 


Michael, max 1000 characters? Even if you set the datatype to Memo within the control?


Hello,


 


If you use "Memo" you can set that manually in the control properties under Validation, but for minimum length required there is no direct way for that. That is something I would suggest at https://ideas.k2.com/.


 


Thanks,


Michael


Hi Sharpharp1, 


 


It looks like you can set a minimum and maximum allowed number of words using a regex. It will not prevent the user from entering more than 2000 words, however it can notify them on an action that the number of words exceeds the limit. 


 


The Regex to make sure that the number of words is between 1000 and 2000 is ^W*(w+(W+|$)){1000,2000}$


 


See the attachment for my configuration


 


I'm still working out a way to count the number of words in the text area.


Hi Emily,

 

Thanks for that and the step-by-step, really appreciate it.

 

Just tried your suggestion and the True/false thing works well, so I can use that part when the user clicks submit to validate the entry -Only issue there is that the user would have to keep re-editing and submitting without knowing how many words are typed real-time.

 

I did find this post which is meant to display the word count: http://community.k2.com/t5/K2-blackpearl/Word-count-on-a-text-control/td-p/99327/page/3

But i don't understand the steps involved (lost me on the parent child data label, text area bit) would you perhaps make any sense of it or see if this can give you the word count in real-time?

 

I am all about the user experience, so this is definitely something i would need to implement.

 

Thanks


Hi Sharpharp1, 


 


Okay, so I was able to get this working using the other community post you linked. It doesn't seem to reduce the word count to 0 though. 


Hi Emily,

 

The magic step was having it all in one CELL...... Wow.

Thank you for the step by step, i'm sure everyone will benefit from your guide.

 

Now if only my other query was possible (redirecting workflows if you are a non-admin)

 

Really appreciate it Emily, have some Kudos.

 


Hi,

 

Found a problem uncovered by some test users...

 

If you cut and paste any text into the text area, it does not update the count (until someone presses the spacebar afterwards)

 

100% of users will be confused as to why the count hasn't updated...

 

So is there any way of updating the count if a user copies and pastes some text into the box?

 

Thanks


Got this code which works in jfiddle for detecting pasted text:

 

$(document).ready(function() {
var wrdCountDataLabel = $(";name='WordCount']");
wrdCountDataLabel.parent().find('inputttype=text], textarea').on("keydown paste cut", function() {
var me = this
setTimeout(function() {
var s = $(me).val().replace(/(^s*)|(s*$)/gi, "").replace(// ]{2,}/gi, " ").replace(/
/, "
");
var wordCount = s.split(" ").length;
if (wordCount === NaN) wordCount = 0;
wrdCountDataLabel.val(wordCount);


})
});
})

The above code works in jfiddle when pasting text into a textarea, but if add scripts tags around it and add it to my K2 form textarea, the count is not updated when PASTING in text.

 

Anyone able to advise?


Another issue with this is that i do a LOAD method on a field with the text in and need a word count for that... Transferring the data in via load method does not activate the word count either...

 

Anyone?????


Here is a working one:


 


 


<script>
$(document).ready(function() {
var wrdCountDataLabel = $("[name='WordCount']");
wrdCountDataLabel.parent().find('input[type=text], Textarea').on("keydown paste cut", function() {
var me = this;
setTimeout(function() {
var s = $(me).val().replace(/(^s*)|(s*$)/gi, "").replace(/[ ]{2,}/gi, " ").replace(/
/, "
");
var wordCount = s.split(" ").length;
if (wordCount === NaN) wordCount = 0;
$("[name='WordCount']").SFCLabel('option', 'text', wordCount);


})
});
})
</script>

 


 


 


In order to get it working with the load method, you need to add the following action after the load method:


 


then execute TextArea control's Focus method

 


and update the following line in your script to include focus, change and click


 


wrdCountDataLabel.parent().find('input[type=text], Textarea').on("keydown paste cut change click focus".....

 


Yeah, that's what i'm talking about. Kudos x100 Mustafa!!!


So - I've been struggling with this almost exact situation today where I'm trying to count the characters - not the words.

 

KUDOS to figuring out you have to have everything in the same cell.   Got me one step closer.

 

But, has anybody figured out how to get character count and not just words?

 

 


Hi,
Have you done for the word count? if yes, can you please share the code snippet for reference.

Reply