November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi,
In EPiServer 6 you could hook to a DataFactory events or prepare a custom property. In EPiServer 7/8 you there is EPiServer.Validation.IValidate<T> interface.
Hi Grzegorz yes this I know, but how do after you done your comparison in Datafactory events send a response back to the user interface displaying for the user that the userinput is wrong.
"Your stopdate should be later than startdate".
/C
Did you check the CancelReason property? Maybe it could be used.
private void Instance_SavingContent(object sender, ContentEventArgs e)
{
e.CancelAction = true;
e.CancelReason = "Your stopdate should be later than startdate";
}
I would recommend to create a custom validator instead. It's easier and more convenient.
Here's an example for validating start and stop dates for a calendar event (CalendarEventPage), given that there is two properties called EventStartDate and EventStopDate in the content type.
public class CalendarEventPageValidator : IValidate<CalendarEventPage> { public IEnumerable<ValidationError> Validate(CalendarEventPage instance) { if (instance.EventStartDate == null || instance.EventStopDate == null) { yield return new ValidationError { ErrorMessage = "An event start and stop date must be specified", PropertyName = "EventStartDate", RelatedProperties = new string[] { "EventStartDate", "EventStopDate" }, Severity = ValidationErrorSeverity.Error, ValidationType = ValidationErrorType.StorageValidation }; } else if (instance.EventStartDate > instance.EventStopDate) { yield return new ValidationError { ErrorMessage = "The event start date must occur before the stop date", PropertyName = "EventStartDate", RelatedProperties = new string[] { "EventStartDate", "EventStopDate" }, Severity = ValidationErrorSeverity.Error, ValidationType = ValidationErrorType.StorageValidation }; } yield break; } }
Just add this class and compile. Done.
Hi
Is this possible to achive? In Episerver CMS 6R2 in my Pagetype I got two properties of type DateTime (Start ad Stop).
To prevent the users to enter a later date as Start compared to Stop.
Would it be possible to do a compare of those when the user enters the vaules and display this error to the user (like in the manner when a property is required). My intention was to hook something in the pagesave event, but is it possible to send back some nice response to user after the datecheck from that event or can this be done in some other way?