Word Counting, and Word Count Limit.

New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

I have a  multilined field named "Bio" that needs to have the words typed, counted. This field must also not allow the user to type in more then 65 words.  If less than 65 words the field is editable.  At 65 words the field becomes locked or read only. There is also field on the form, named "WordCount." This field will get/display the total words typed in the "Bio" field.

I hope someone can help.

Thanks for your replies!  However I finally got this thing figures out with scripting!  I place the following code in the document level:

Script Name: wordsMax

The code:

function limit_words_ks(max_words)

{

// Get all of the characters in the field

   var s = AFMergeChange(event);

// Reject if more than max_num words

   if (s.split(/[ ]+/).length > max_words) {

      app.alert("You can't enter more than 65 words to this field.");

      event.rc = false;

   }

}

In the field to be typed in I added the following Javascript into the Custom Key Stroke Script:

The code:

{

    var Bio = event.value.split(" ");

    this.getField("WordCount").value = Bio.length;

    limit_words_ks(65);

}

The result was the word input in the field were totaled in the field "WordCount.", When the user attempted to go past 65 words an alert window popped up telling the user "You can't enter more than 65 words to this field."  The user could remove words, but not add.

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

530

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Word Counting, and Word Count Limit.

New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

I have a  multilined field named "Bio" that needs to have the words typed, counted. This field must also not allow the user to type in more then 65 words.  If less than 65 words the field is editable.  At 65 words the field becomes locked or read only. There is also field on the form, named "WordCount." This field will get/display the total words typed in the "Bio" field.

I hope someone can help.

Thanks for your replies!  However I finally got this thing figures out with scripting!  I place the following code in the document level:

Script Name: wordsMax

The code:

function limit_words_ks(max_words)

{

// Get all of the characters in the field

   var s = AFMergeChange(event);

// Reject if more than max_num words

   if (s.split(/[ ]+/).length > max_words) {

      app.alert("You can't enter more than 65 words to this field.");

      event.rc = false;

   }

}

In the field to be typed in I added the following Javascript into the Custom Key Stroke Script:

The code:

{

    var Bio = event.value.split(" ");

    this.getField("WordCount").value = Bio.length;

    limit_words_ks(65);

}

The result was the word input in the field were totaled in the field "WordCount.", When the user attempted to go past 65 words an alert window popped up telling the user "You can't enter more than 65 words to this field."  The user could remove words, but not add.

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

531

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 24, 2019 0
Most Valuable Participant ,
Jul 24, 2019

Copy link to clipboard

Copied

Locking the field is a bad idea. What if the user made a mistake and wants to go back and edit it?

It's better to not allow more than 65 words to be entered by reject any new input when that happens.

To do that you would need to use a custom Keystroke script.

I've developed a similar (paid-for) tool that can count words "live" as the user types them into a field. It wouldn't be too hard to adjust it to also stop the user from entering more than a specific amount of words into it. You can find it here: Custom-made Adobe Scripts: Acrobat -- "Live" Characters and Words Counter

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0
Adobe Community Professional ,
Jul 25, 2019

Copy link to clipboard

Copied

Word counts are not the best way to limit input on a field. Instead, set the field to allow multiline input but not to allow scrolling long text. Then set the font size (not auto). Acrobat will then allow the user to enter as much text as fits within the boundaries of the field given the font size and then beep if they enter too much. This allows you to be flexible with word length and number of words while still limiting the amount of text entered.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 25, 2019 0
New Here ,
Jul 26, 2019

Copy link to clipboard

Copied

Thanks for your replies!  However I finally got this thing figures out with scripting!  I place the following code in the document level:

Script Name: wordsMax

The code:

function limit_words_ks(max_words)

{

// Get all of the characters in the field

   var s = AFMergeChange(event);

// Reject if more than max_num words

   if (s.split(/[ ]+/).length > max_words) {

      app.alert("You can't enter more than 65 words to this field.");

      event.rc = false;

   }

}

In the field to be typed in I added the following Javascript into the Custom Key Stroke Script:

The code:

{

    var Bio = event.value.split(" ");

    this.getField("WordCount").value = Bio.length;

    limit_words_ks(65);

}

The result was the word input in the field were totaled in the field "WordCount.", When the user attempted to go past 65 words an alert window popped up telling the user "You can't enter more than 65 words to this field."  The user could remove words, but not add.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2019 0
try67 LATEST
Most Valuable Participant ,
Jul 26, 2019

Copy link to clipboard

Copied

That is a script...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2019 0