Restrict the asset details to get saved | Community
Skip to main content
Level 2
October 3, 2022
Solved

Restrict the asset details to get saved

  • October 3, 2022
  • 3 replies
  • 1244 views

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...

 

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 mahi1365

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.

3 replies

Level 4
October 3, 2022

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.

mahi1365Author
Level 2
October 3, 2022

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.

 

 

Level 4
October 3, 2022

^$|^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.

Mayank_Gandhi
Adobe Employee
Adobe Employee
October 3, 2022

@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.

mahi1365AuthorAccepted solution
Level 2
October 10, 2022

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.