ensure culture carries through to child model state and ensure language culture is carried through on the block content scaffolds
This commit is contained in:
@@ -89,7 +89,6 @@ function valPropertyMsg(serverValidationManager, localizationService, angularHel
|
||||
var errCount = angularHelper.countAllFormErrors(formCtrl);
|
||||
|
||||
if (errCount === 0) {
|
||||
resetError();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -176,6 +176,19 @@
|
||||
|
||||
if (block === null) return null;
|
||||
|
||||
// ensure that the containing content variant language/culture is transfered along
|
||||
// to the scaffolded content object representing this block. This is required for validation
|
||||
// along with ensuring that the umb-property inheritance is constently maintained.
|
||||
if (vm.umbVariantContent.editor.content.language) {
|
||||
block.content.language = vm.umbVariantContent.editor.content.language;
|
||||
// currently we only ever deal with invariant content for blocks so there's only one
|
||||
block.content.variants[0].tabs.forEach(tab => {
|
||||
tab.properties.forEach(prop => {
|
||||
prop.culture = vm.umbVariantContent.editor.content.language.culture;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
block.view = (block.config.view ? "/" + block.config.view : getDefaultViewForBlock(block));
|
||||
|
||||
block.hideContentInOverlay = block.config.forceHideContentEditorInOverlay === true || inlineEditing === true;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Umbraco.Web
|
||||
internal static void AddPropertyError(this System.Web.Http.ModelBinding.ModelStateDictionary modelState,
|
||||
ValidationResult result, string propertyAlias, string culture = "", string segment = "")
|
||||
{
|
||||
modelState.AddPropertyValidationError(new ContentPropertyValidationResult(result), propertyAlias, culture, segment);
|
||||
modelState.AddPropertyValidationError(new ContentPropertyValidationResult(result, culture, segment), propertyAlias, culture, segment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -11,10 +11,15 @@ namespace Umbraco.Web.PropertyEditors.Validation
|
||||
/// </remarks>
|
||||
public class ContentPropertyValidationResult : ValidationResult
|
||||
{
|
||||
public ContentPropertyValidationResult(ValidationResult nested)
|
||||
private readonly string _culture;
|
||||
private readonly string _segment;
|
||||
|
||||
public ContentPropertyValidationResult(ValidationResult nested, string culture, string segment)
|
||||
: base(nested.ErrorMessage, nested.MemberNames)
|
||||
{
|
||||
ComplexEditorResults = nested as ComplexEditorValidationResult;
|
||||
_culture = culture;
|
||||
_segment = segment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -35,7 +40,7 @@ namespace Umbraco.Web.PropertyEditors.Validation
|
||||
if (ComplexEditorResults == null)
|
||||
return base.ToString();
|
||||
|
||||
var json = JsonConvert.SerializeObject(this, new ValidationResultConverter());
|
||||
var json = JsonConvert.SerializeObject(this, new ValidationResultConverter(_culture, _segment));
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,20 @@ namespace Umbraco.Web.PropertyEditors.Validation
|
||||
/// </remarks>
|
||||
internal class ValidationResultConverter : JsonConverter
|
||||
{
|
||||
private readonly string _culture;
|
||||
private readonly string _segment;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="culture">The culture of the containing property which will be transfered to all child model state</param>
|
||||
/// <param name="segment">The segment of the containing property which will be transfered to all child model state</param>
|
||||
public ValidationResultConverter(string culture = "", string segment = "")
|
||||
{
|
||||
_culture = culture;
|
||||
_segment = segment;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) => typeof(ValidationResult).IsAssignableFrom(objectType);
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
@@ -88,14 +102,14 @@ namespace Umbraco.Web.PropertyEditors.Validation
|
||||
// "errors/propertyHasErrors" message, however I think that leaves for less flexibility since it could/should be
|
||||
// up to the front-end validator to show whatever message it wants (if any) for an error indicating a nested property error.
|
||||
// Will leave blank.
|
||||
modelState.AddPropertyValidationError(new ValidationResult(string.Empty), propTypeResult.PropertyTypeAlias);
|
||||
modelState.AddPropertyValidationError(new ValidationResult(string.Empty), propTypeResult.PropertyTypeAlias, _culture, _segment);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var v in result)
|
||||
{
|
||||
modelState.AddPropertyValidationError(v, propTypeResult.PropertyTypeAlias);
|
||||
modelState.AddPropertyValidationError(v, propTypeResult.PropertyTypeAlias, _culture, _segment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user