From 1e32ffe222d5d9387b12d887ec0970c2d29855ff Mon Sep 17 00:00:00 2001 From: Rasmus John Pedersen Date: Wed, 23 Sep 2015 14:44:00 +0200 Subject: [PATCH 1/2] Added nested property editor validation support --- .../NestedContentPropertyEditor.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs b/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs index 6332798..5afde2a 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,16 @@ 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)) + { + yield return result; + } + } // Check mandatory if (propType.Mandatory) From f471cd551c42677db45635fdcd34f32f70c74dd9 Mon Sep 17 00:00:00 2001 From: Rasmus John Pedersen Date: Tue, 29 Sep 2015 14:08:35 +0200 Subject: [PATCH 2/2] Prefix validation message with property name. --- .../PropertyEditors/NestedContentPropertyEditor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs b/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs index 5afde2a..d8741d3 100644 --- a/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Our.Umbraco.NestedContent/PropertyEditors/NestedContentPropertyEditor.cs @@ -353,6 +353,7 @@ public IEnumerable Validate(object rawValue, PreValueCollectio { foreach (ValidationResult result in validator.Validate(propValues[propKey], propPrevalues, propertyEditor)) { + result.ErrorMessage = "Item " + (i + 1) + " '" + propType.Name + "' " + result.ErrorMessage; yield return result; } }