diff --git a/src/Altinn.App.Core/Configuration/AppSettings.cs b/src/Altinn.App.Core/Configuration/AppSettings.cs
index c229a6e9a..ab34f341d 100644
--- a/src/Altinn.App.Core/Configuration/AppSettings.cs
+++ b/src/Altinn.App.Core/Configuration/AppSettings.cs
@@ -224,8 +224,18 @@ public string GetResourceFolder()
public string AppVersion { get; set; }
///
- /// Enable the preview functionality to load layout in backend and remove data from hidden components before validation and task completion
+ /// Enable the functionality to load layout in backend and remove data from hidden components before task completion
///
- public bool RemoveHiddenDataPreview { get; set; } = false;
+ public bool RemoveHiddenData { get; set; } = false;
+
+ ///
+ /// Enable the functionality to load layout in backend and validate required fields as defined in the layout
+ ///
+ public bool RequiredValidation { get; set; } = false;
+
+ ///
+ /// Enable the functionality to run expression validation in backend
+ ///
+ public bool ExpressionValidation { get; set; } = false;
}
}
diff --git a/src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs b/src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs
index de2b33811..a95aff431 100644
--- a/src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs
+++ b/src/Altinn.App.Core/Features/Validation/ValidationAppSI.cs
@@ -228,19 +228,29 @@ public async Task> ValidateDataElement(Instance instance,
object data = await _dataClient.GetFormData(
instanceGuid, modelType, instance.Org, app, instanceOwnerPartyId, Guid.Parse(dataElement.Id));
- if (_appSettings.RemoveHiddenDataPreview)
+ LayoutEvaluatorState? evaluationState = null;
+
+ // Remove hidden data before validation
+ if (_appSettings.RequiredValidation || _appSettings.ExpressionValidation)
{
+
var layoutSet = _appResourcesService.GetLayoutSetForTask(dataType.TaskId);
- var evaluationState = await _layoutEvaluatorStateInitializer.Init(instance, data, layoutSet?.Id);
- // Remove hidden data before validation
+ evaluationState = await _layoutEvaluatorStateInitializer.Init(instance, data, layoutSet?.Id);
LayoutEvaluator.RemoveHiddenData(evaluationState);
- // Evaluate expressions in layout and validate that all required data is included and that maxLength
- // is respected on groups
- var layoutErrors = LayoutEvaluator.RunLayoutValidationsForRequired(evaluationState, dataElement.Id);
+ }
+
+ // Evaluate expressions in layout and validate that all required data is included and that maxLength
+ // is respected on groups
+ if (_appSettings.RequiredValidation)
+ {
+ var layoutErrors = LayoutEvaluator.RunLayoutValidationsForRequired(evaluationState!, dataElement.Id);
messages.AddRange(layoutErrors);
+ }
- // Run expression validations
- var expressionErrors = ExpressionValidator.Validate(dataType.Id, _appResourcesService, new DataModel(data), evaluationState, _logger);
+ // Run expression validations
+ if (_appSettings.ExpressionValidation)
+ {
+ var expressionErrors = ExpressionValidator.Validate(dataType.Id, _appResourcesService, new DataModel(data), evaluationState!, _logger);
messages.AddRange(expressionErrors);
}
diff --git a/src/Altinn.App.Core/Implementation/DefaultTaskEvents.cs b/src/Altinn.App.Core/Implementation/DefaultTaskEvents.cs
index 934065eb1..0efa1cb57 100644
--- a/src/Altinn.App.Core/Implementation/DefaultTaskEvents.cs
+++ b/src/Altinn.App.Core/Implementation/DefaultTaskEvents.cs
@@ -165,7 +165,7 @@ public async Task OnEndProcessTask(string endEvent, Instance instance)
private async Task RunRemoveHiddenData(Instance instance, Guid instanceGuid, List? dataTypesToLock)
{
- if (_appSettings?.RemoveHiddenDataPreview == true)
+ if (_appSettings?.RemoveHiddenData == true)
{
await RemoveHiddenData(instance, instanceGuid, dataTypesToLock);
}
@@ -269,9 +269,9 @@ private async Task RemoveHiddenData(Instance instance, Guid instanceGuid, List