AEM Asset Metadata schema custom validation | Community
Skip to main content
ravindrareddydr
Level 2
September 24, 2017
Solved

AEM Asset Metadata schema custom validation

  • September 24, 2017
  • 3 replies
  • 4235 views

HI Team,

I hope i am asking valid point.

As we know , We can create a custom Meataschema profile in AEM from below URL

http://localhost:4502/mnt/overlay/dam/gui/content/metadataschemaeditor/schemalist.html?formPath=/conf/global/settings/dam/adminui-extension/metadataschema

My Question is

I would like create a custom validation for a form field instead of only Required field in Form in Metadata schema.

Example : i would like add Regex for entering text in Name field with chars limit.

I am trying as below, issue here is showing error but i am unable to stop saving the data, when i click on Save its not stopping

<script>

jQuery.validator.register({

  selector: "[data-myapp-maxlength]",

  validate: function(el) {

    var maxlength = parseInt(el.attr("data-myapp-maxlength"), 10);

    if (isNaN(maxlength)) {

      return;

    }

    var length = el.val().length;

    if (length > maxlength) {

      return "The field needs to be maximum " + maxlength + " characters. It currently has a length of " + length + ".";

    }

  }

});

</script>

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 kautuk_sahni

See this blog:- AEM Touch UI Custom Validation - Adobe Experience Manager | AEM/CQ | Apache Sling

//

The selector property ties the validator to the form elements on the page. The property accepts any jQuery selector such as a class ( .my-class-name), type ( INPUT) or attribute ( INPUT[type="text"]) selectors. The validate property is the function that validates the form element's input. The function provides the form element as a jQuery object as the single available parameter. The field is treated as invalid if this function returns a string literal as the validation error message.

Also note that:

show: The function to show the error. The function can return {@link Validators.CONTINUE} or {@link Validators.STOP}.

Clear: The function to clear the error. The function can return {@link Validators.CONTINUE} or {@link Validators.STOP}.

 

More Examples :- GitHub - nateyolles/aem-touch-ui-validation: AEM Touch UI Validation Library

~kautuk

3 replies

kautuk_sahni
Community Manager
kautuk_sahniCommunity ManagerAccepted solution
Community Manager
September 25, 2017

See this blog:- AEM Touch UI Custom Validation - Adobe Experience Manager | AEM/CQ | Apache Sling

//

The selector property ties the validator to the form elements on the page. The property accepts any jQuery selector such as a class ( .my-class-name), type ( INPUT) or attribute ( INPUT[type="text"]) selectors. The validate property is the function that validates the form element's input. The function provides the form element as a jQuery object as the single available parameter. The field is treated as invalid if this function returns a string literal as the validation error message.

Also note that:

show: The function to show the error. The function can return {@link Validators.CONTINUE} or {@link Validators.STOP}.

Clear: The function to clear the error. The function can return {@link Validators.CONTINUE} or {@link Validators.STOP}.

 

More Examples :- GitHub - nateyolles/aem-touch-ui-validation: AEM Touch UI Validation Library

~kautuk

Kautuk Sahni
Adobe Employee
January 26, 2018

Where should we place this javascript in case of custom metadata schema validation?

June 28, 2018

did you solve your problem? I'm also looking for the same thing