Expand my Community achievements bar.

Adding restriction to the comment field

Avatar

Level 3

How to add minimum characters restriction for the "Step Back Item" comment field in the aem/inbox.

I overriden the comment field but when i try to add js it is not reflecting.

HelpTech_0-1741096089256.pngHelpTech_1-1741096123409.png

I am using AEM 6.5 version

3 Replies

Avatar

Level 9

Hi @HelpTech ,

 

Could you please provide more details how you add clientlibs (categories) and validation code?

 

I checked this code and would suggest you to create clientlibrary with categories=[cq.inbox.gui.validation].

 

Please, use Granite UI JS validation to validate your field.

Example of node (overlay /apps/cq/inbox/content/inbox/dialogs/workitemcompletedialog/items/form/items/comment):

<comment
    jcr:primaryType="nt:unstructured"
    fieldLabel="Comment"
    name="comment"
    rows="4"
    sling:resourceType="granite/ui/components/coral/foundation/form/textarea"
    validation="textarea.min-length">
   <granite:data jcr:primaryType="nt:unstructured" min-length="5"/>
</comment>

 

Example of JS code:

(function(window, $, Granite) {
    "use strict";

    $(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
        selector: "[data-foundation-validation~='textarea.min-length']",
        validate: function(el) {
            var v = el.value;
            var minLength = $(el).data("minLength");

            if (minLength) {
               return;
            }
            
            return v && v.length < minLength ? Granite.I18n.get("Your validation message") : null;
        }
    });
})(window, Granite.$, Granite);

 

Best regards,

Kostiantyn Diachenko.

Avatar

Level 3

Hi @konstantyn_diachenko 
I am creating the clientlibrary under the dialog /apps/cq/inbox/content/inbox/dialogs/clientlib-inbox, when i tried adding the category and the js still the js is not getting reflected and I am unable to get the validation work.

HelpTech_0-1741156192037.png

 

Avatar

Level 9

Hi @HelpTech ,

 

Does your /apps/cq/inbox/content/inbox/dialogs/clientlib-inbox have jcr:primaryType="cq:ClientLibraryFolder" ? Does it have js.txt that references your js file?

 

If yes, please try to rebuild clientlibraries via http://localhost:4502/libs/granite/ui/content/dumplibs.html

 

Best regards,

Kostiantyn Diachenko.