Expand my Community achievements bar.

SOLVED

Validate the name field on paste

Avatar

Level 2

On the paste page form shown below, I need to restrict the input to prevent capital letters. We have something similar on our form for creating new pages, but this doesn't seem to be working when I include a selector for the name field on the paste form.

This is the form where I need to prevent capital letters:

jeremyc82321732_1-1670270688432.png

This code prevents capital letters on new pages:

var pageNamePattern = /^[a-z0-9_\-,]+$/; // remove A-Z from this regex so that authors cannot use upper-cased characters
    $(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
        selector: '[data-foundation-validation~="admin.pagename"]',
        validate: function(el) {
            var valid = pageNamePattern.test(el.value) || el.value === "";

            if (!valid) {
                return Granite.I18n.get("mycompany.validation.page_name_regex");
            }
        }
    });

The field name on the paste form does not have a `data-foundation-validation` value, so I'm using the selector `#pastePageDialog input` for a test. When I try this, the validation does not stop me from entering capital letters.

Any ideas?
Thanks!
Jeremy

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

hi @jeremyc82321732 ,

 

Please check this out AEM: Dialog Field Validations (aemhub.blogspot.com) 

 

Hoping this helps.

 

Thanks,

Nikita Garg

View solution in original post

3 Replies

Avatar

Employee Advisor

hi @jeremyc82321732 ,

 

Your validation might be overriden by OOTB validation on name field. On the name field, i checked this JS is getting applied. So, you can debug and check.

 

Nikita___Garg_0-1670301070225.png

Thanks,

Nikita Garg

Avatar

Level 2

No matter what I try, the selector I was using is not getting caught.  Instead of changing the selector on this function (which works on other instances), is there a way to add the attribute `data-foundation-validation="admin.pagename"` to the name field on the paste form?  This way I do not need to alternate a JavaScript that is already working.

Avatar

Correct answer by
Employee Advisor

hi @jeremyc82321732 ,

 

Please check this out AEM: Dialog Field Validations (aemhub.blogspot.com) 

 

Hoping this helps.

 

Thanks,

Nikita Garg