Field validation

I created a multifield as showed below, but i would like to have validation for my socialMediaLink (that is defined as a string). So when the user press save on entered data it would regex validate the string as an url.
new FieldDefinition(“SocialMedia”, SystemFieldTypeConstants.MultiField)
{
Localizations =
{
[“sv-SE”] = {Name = “Social Media” },
},
CanBeGridColumn = false,
CanBeGridFilter = true,
Option = new MultiFieldOption
{
IsArray = true,
Fields = new List()
{
“SocialMediaIcon”,
“SocialMediaIconText”,
"SocialMediaIconLink"
}
}
}

Litium version: 7.2

You can add validation so that when the entity is saved, it will check that the field contains a valid URL and display an error if that’s not the case.
https://docs.litium.com/documentation/architecture/validation

An example can be found in this task from our developer education: https://github.com/LitiumAB/Education/tree/master/Developer%20Education/Bookstore/Validation

My guess is that this will be in the CMS, so the entity would either be DraftPage or DraftBlock if you want the error to be shown on Save. Otherwise it will be shown on Publish.

1 Like