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...
Solved! Go to Solution.
Views
Replies
Total Likes
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.
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.
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.
^$|^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.
@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.
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.