Expand my Community achievements bar.

SOLVED

AEM Asset Metadata schema custom validation

Avatar

Level 3

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=/con...

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>

1 Accepted Solution

Avatar

Correct answer by
Administrator

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

View solution in original post

3 Replies

Avatar

Correct answer by
Administrator

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

Avatar

Employee

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

Avatar

Level 1

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