AEM Asset Metadata schema custom validation | Community
Skip to main content
ravindrareddydr
Level 2
Sep 24, 2017 6:04 PM UTC
Solved

AEM Asset Metadata schema custom validation

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.
kautuk_sahni
kautuk_sahniAccepted solution
Employee
Sep 25, 2017 8:30 AM UTC

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

3 replies

New Participant
Jun 28, 2018 8:43 PM UTC

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

Translate
Employee
Jan 26, 2018 4:57 PM UTC

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

Translate
kautuk_sahni
kautuk_sahniAccepted solution
Employee
Sep 25, 2017 8:30 AM UTC

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

Translate
Kautuk Sahni