I have a form with a few fields where my users will enter content.  It is my intent to limit the amount to text entered, but rather than add a character limit, I would like add some word count counter feature with the field.  Something like (150 of 300 words used) so the user knows they are approaching the word limit.  I would prefer a word limit over a character limit as I want to provide guidance rather than forced limitation.

Thanks

 





 
 Solved!
 
 [Go to Solution.](/t5/adobe-experience-manager-forms/text-field-content-limits/m-p/366789#M724)
Hi [@jmackesy](/t5/user/viewprofilepage/user-id/17379853) 

 

You will have to use Granite validator to apply this check. I have  created a sample code for the same functionality. 

 

Follow these steps:

1. Create clientlibs with category "cq.authoring.dialog"

2. Add this js

 

 


```
(function ($) {
    'use strict';

    $(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
	    selector: ".custom-word-limit",
	    validate: function(element) {
	        var elementValue = element.value;
            var wordLimit = element.dataset.wordLimit;
	        if(elementValue && wordLimit && elementValue.split(' ').filter(function(n) { return n != '' }).length > wordLimit){
				return "Word limit for the field is " + wordLimit;
	        }
	    }
	});

}(Granite.$));
```
 

 

3. Add granite:class property with value "custom-word-limit" to the textfield where you want to apply this word limit check like this:  
![Screenshot from 2020-06-16 16-13-48.png](https://experienceleaguecommunities.adobe.com/t5/image/serverpage/image-id/24800i9C7A178970CAFA67/image-size/large?v=v2&px=999 "Screenshot from 2020-06-16 16-13-48.png")

4. Then add a "granite:data" node under the textfield of type nt:unstructured and add property word-limit = 100. Change this number to any number of which you want to apply the limit for this particular field like this  
![Screenshot from 2020-06-16 16-16-08.png](https://experienceleaguecommunities.adobe.com/t5/image/serverpage/image-id/24801i9084A81E19FC20EB/image-size/large?v=v2&px=999 "Screenshot from 2020-06-16 16-16-08.png")

5. The author will get message like this

![Screenshot from 2020-06-16 16-18-32.png](https://experienceleaguecommunities.adobe.com/t5/image/serverpage/image-id/24802i6496D669DCAA5703/image-size/large?v=v2&px=999 "Screenshot from 2020-06-16 16-18-32.png")

 

Try this and let me know if it works for you.

Thanks,

Nupur




[View solution in original post](/t5/adobe-experience-manager-forms/text-field-content-limits/m-p/366789#M724)
hi katie,

there a certainly mixed reviews on the worth of a conclusion. i personally recommend that my students write one that is 4-5 sentences long. however, i encourage them to only spend 3-4 minutes writing one. in general, you want to spend as much time as you can writing your body paragraphs … hey [@skyler.sorensen](/u/skyler.sorensen), welcome to the auth0 community!

this error is appearing because of the following limitation:

[image]

[metadata best practices](https://auth0.com/docs/best-practices/metadata-best-practices#metadata-storage-and-size-limits)

best practices for metadata in auth0.

metadata is allowed 10 strings with max 500 chars. may be you can breakdown … This is usually done by giving each submit button a unique id/name:



```
<input id="sub1" name="sub1" type="submit" value="Submit Form 1" />
```

it's a rubbish name/id, I know, but you get the idea. Then in your form handling routine:



```
if(isset($_POST['sub1'])){
  //code for handling this form
}
``` You could achieve this with a simple `for` loop:



```
var min = 12,
    max = 100,
    select = document.getElementById('selectElementId');

for (var i = min; i<=max; i++){
    var opt = document.createElement('option');
    opt.value = i;
    opt.innerHTML = i;
    select.appendChild(opt);
}

```

[JS Fiddle demo](https://jsfiddle.net/davidThomas/NX3ac/).


[JS Perf](https://jsperf.com/) comparison of both mine and [Sime Vidas' answer](https://jsperf.com/comparison-of-loops), run because I thought his looked a little more understandable/intuitive than mine and I wondered how that would translate into implementation. According to Chromium 14/Ubuntu 11.04 mine is somewhat faster, other browsers/platforms are likely to have differing results though.







**Edited** in response to comment from OP:



> 
> [How] do [I] apply this to more than one element?
> 
> 
> 



```
function populateSelect(target, min, max){
    if (!target){
        return false;
    }
    else {
        var min = min || 0,
            max = max || min + 100;

        select = document.getElementById(target);

        for (var i = min; i<=max; i++){
            var opt = document.createElement('option');
            opt.value = i;
            opt.innerHTML = i;
            select.appendChild(opt);
        }
    }
}
// calling the function with all three values:
populateSelect('selectElementId',12,100);

// calling the function with only the 'id' ('min' and 'max' are set to defaults):
populateSelect('anotherSelect');

// calling the function with the 'id' and the 'min' (the 'max' is set to default):
populateSelect('moreSelects', 50);

```

[JS Fiddle demo](https://jsfiddle.net/davidThomas/NX3ac/1/).


And, finally (after quite a delay...), an approach extending the prototype of the `HTMLSelectElement` in order to chain the `populate()` function, as a method, to the DOM node:



```
HTMLSelectElement.prototype.populate = function (opts) {
    var settings = {};

    settings.min = 0;
    settings.max = settings.min + 100;

    for (var userOpt in opts) {
        if (opts.hasOwnProperty(userOpt)) {
            settings[userOpt] = opts[userOpt];
        }
    }

    for (var i = settings.min; i <= settings.max; i++) {
        this.appendChild(new Option(i, i));
    }
};

document.getElementById('selectElementId').populate({
    'min': 12,
    'max': 40
});

```

[JS Fiddle demo](https://jsfiddle.net/davidThomas/NX3ac/148/).


References:


* [`node.appendChild()`](https://developer.mozilla.org/en/DOM/node.appendChild).
* [`document.getElementById()`](https://developer.mozilla.org/en/DOM/document.getElementById).
* [`element.innerHTML`](https://developer.mozilla.org/en/DOM/element.innerHTML). if you’re talking about easel…

select the text that you want to change

go to the cut shape tab

click on the shape tab and look at the bottom of the tab and you will see the font name that you have selected

you can pick the font you want.

hope that’s what you were talking about

good luck

russe… don't think you can automate this yet, you at best would have to put in the comment manually You need to give the user the option of typing in a value that represents that there are no more values to enter. Perhaps give a prompt like:



```
Please enter a value.  Enter -999999 if you have no more values [B]:[/B]
```

As for the ten (or fewer) values, you should probably have an array and a loop instead of ten separate variable names and ten separate cin statements. So you're looking at something like this:



```
double dValue[10];
    int numEntries = 0;
    double sum = 0;
    
    while (numEntries < 10)
    {
          cout << "Enter number (-999999 to stop) : ";
          cin >> dValue[numEntries];
          // check whether dValue[numEntries] == -999999
          // if so, short-circuit the loop with the "break" command
            
          // increment numEntries
          // adjust sum
    }
```

As a side note, I picked -999999 as the value to represent no more values because



1. It's an integer, so it can be represented exactly as a double (no round-off error using == to compare).
2. It's a number that, chances are, people wouldn't actually want to add, so it's sort of "out of the way". Chances are, few people want to add -999999. If they do, they can't use this program! if you visit admin > customize > embedding you can change “maximum number of posts to embed” to a higher value. form\_title= bath decor form\_header= give your home a new look
with new bath decor! what is the square footage of your bathroom?*=
\_ [50] what is your design style?*= \_ [50] what is your budget for
the decor?*= \_ [50] well, in a texting/typing situation you can't hear what that person is saying, but caps specify raised voices. if you are new to the internet, you should try doing a google search for "netiquette", it will help you get a general grasp of things.