Adding validation to custom orchard settings

Topics: Troubleshooting
Jun 29, 2012 at 7:22 PM

Hello,

I've added some custom settings to the settings section of orchard. I tried adding some validation to the drivers (is that an inappropriate place?) so that they look something like this:

protected override DriverResult Editor(EmailSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
	updater.TryUpdateModel(part, Prefix, nullnull);
 
	if (!emailRegex.IsMatch(part.MemberSupportEmailAddress))
		updater.AddModelError(Prefix, T("You must specify a valid email for the support to email address."));
 
	return ContentShape(Shape, () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix))
		.OnGroup(SettingDisplayName);
}

 

But then I found that when I hit the save button the driver is actually getting called for all my settings (so if I have an invalid setting on one page, the error will get added on any settings page where I hit save).

Is there a better way to go about this?

Thanks