Expand my Community achievements bar.

SOLVED

Restrict the asset details to get saved

Avatar

Level 2

i created a custom field in metadata schema. This field have validation like starts with capital M,S and follow with numeric (ex:MS123 accepted Ms234 error).

This field is not a required fields. if the user don't input any data it should save. if the user input some data/text and the data not follows the patten then we need to restrict the user in saving the asset details.

 

Please help...

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi,

i checked on the html of every field. i found a difference if field have validation and we input the incorrect text/data this 

aria-invalid="true"

will append to the html. i used aria-invalid attribute whenever if aria-invalid="true" the save&close/save should highlight error and should not perform save operation.

View solution in original post

5 Replies

Avatar

Level 4

Hi @mahi1365 ,

 

For validation of the schema fields you can use the foundation validation API and add a regex pattern to validate your requirement.

Try the regex below for your requirement

 

^$|^MS+([\d])*$

 

 

https://medium.com/@theopendle/aem-custom-metadata-forms-for-assets-8c6597205f9d  

 

Hope this helps.

Avatar

Level 2

validation is working fine. the field is not a required field. but when ever user enters wrong pattern  it should restrict the user from saving.

 

 

Avatar

Level 4

^$|^MS+([\d])*$

 

In the above pattern the first part ^$ allows empty string, so empty value will allow saving and second part allows only the pattern, so wrong pattern will restrict the user from saving.

Avatar

Employee Advisor

@mahi1365 on submit/save event you can run a validation check for all the not null fields against their regex pattern and if anything is found to be false then set the focus to the respective with the error at the widget.

Avatar

Correct answer by
Level 2

Hi,

i checked on the html of every field. i found a difference if field have validation and we input the incorrect text/data this 

aria-invalid="true"

will append to the html. i used aria-invalid attribute whenever if aria-invalid="true" the save&close/save should highlight error and should not perform save operation.