Validate the name field on paste | Community
Skip to main content
jeremyc82321732
Level 2
December 5, 2022
Solved

Validate the name field on paste

  • December 5, 2022
  • 1 reply
  • 1453 views

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:

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nikita___Garg

hi @jeremyc82321732 ,

 

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

 

Hoping this helps.

 

Thanks,

Nikita Garg

1 reply

Adobe Employee
December 6, 2022

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.

 

Thanks,

Nikita Garg

jeremyc82321732
Level 2
December 6, 2022

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.

Nikita___GargAdobe EmployeeAccepted solution
Adobe Employee
December 6, 2022

hi @jeremyc82321732 ,

 

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

 

Hoping this helps.

 

Thanks,

Nikita Garg