diff --git a/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs b/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs index 6332798..d8741d3 100644 --- a/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs @@ -327,6 +327,7 @@ public IEnumerable Validate(object rawValue, PreValueCollectio if (value == null) yield break; + IDataTypeService dataTypeService = ApplicationContext.Current.Services.DataTypeService; for (var i = 0; i < value.Count; i++) { var o = value[i]; @@ -345,15 +346,17 @@ public IEnumerable Validate(object rawValue, PreValueCollectio var propType = contentType.PropertyTypes.FirstOrDefault(x => x.Alias == propKey); if (propType != null) { - // It would be better to pass this off to the individual property editors - // to validate themselves and pass the result down, however a lot of the - // validation checking code in core seems to be internal so for now we'll - // just replicate the mandatory / regex validation checks ourselves. - // This does of course mean we will miss any custom validators a property - // editor may have registered by itself, and it also means we can only - // validate to a single depth so having a complex property editor in a - // doc type could get passed validation if it can't be validated from it's - // stored value alone. + PreValueCollection propPrevalues = dataTypeService.GetPreValuesCollectionByDataTypeId(propType.DataTypeDefinitionId); + PropertyEditor propertyEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias); + + foreach (IPropertyValidator validator in propertyEditor.ValueEditor.Validators) + { + foreach (ValidationResult result in validator.Validate(propValues[propKey], propPrevalues, propertyEditor)) + { + result.ErrorMessage = "Item " + (i + 1) + " '" + propType.Name + "' " + result.ErrorMessage; + yield return result; + } + } // Check mandatory if (propType.Mandatory)