Try our conversational search powered by Generative AI!

Episerver Forms Conditional Validation

Vote:
 

Currently struggling with a piece of functionality on an Episerver implementation. 

Basically I need to implement conditional validation on an Episerver Forms field. E.g. TextBox2 is required is TextBox1 has a value of 1, but is not required when TextBox1 has other values.

I have looked into custom validators but I am unclear how I might extend the validator to have additional properties for the field name I want to target and the value it should have in order for the validation to perform the check.

If anybody has any insight on achieving this it would be appreciated.

Thanks

#173315
Dec 20, 2016 16:53
Vote:
 

Don't know if this is too late for you, but this URL has the info you need:

https://www.wearediagram.com/blog/improving-episervers-content-editing-experience-through-validation

 https://gist.github.com/fredrikhaglund/44d494d04e2ffd4e8cbd

In my case:

public IEnumerable<ValidationError> Validate(HomePage instance)
{

if (instance.FooterSettings.ShowChannelOne)
{
if(String.IsNullOrEmpty(instance.FooterSettings.ChannelOneURL) || instance.FooterSettings.ChannelOneIcon == null ||
instance.FooterSettings.ChannelOneHover == null || String.IsNullOrEmpty(instance.FooterSettings.ChannelOneTooltip))
{
return new[]
{
new ValidationError
{
ErrorMessage = "Mandatory to fill out rest of Channel 1 fields (URL, Icons * 2, Tooltip)",
PropertyName = "ShowChannelOne",
Severity = ValidationErrorSeverity.Error
}
};

etc....

#173673
Edited, Jan 04, 2017 16:40
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.