IFormValueAggregator
The SubForm component allows you to group multiple form components together and extract and aggregate values from those components and place them into a single field in the parent form, which could be another SubForm component, or any other form component such as the Document form or Generic form components. How those values are aggregated into a single value is controlled by the selected IFormValueAggregator implementation. Veva contains various implementations, such as the "Concatenate values" aggregator which simply concatenates values with the specified separator.
Instead of implementing the IFormValueAggregator directly, you can also inherit the BaseAggregator and override the GetValues() method. The BaseAggregator gives you access to the ReadValue() method which makes it easy to read a certain value from the form context.
Interface declaration
public interface IFormValueAggregator { object GetValues(Dictionary<string, object> values, FormValueAggregatorContext context); }
Example
The example below shows how the "Concatinate values" aggregator is implemented.
[DisplayName("Concatenate values")] [Description("Simply concatenates all the field values, using the specified separator")] public class ConcatenationFormValueAggregator : BaseAggregator { [EditorBrowsable] [DisplayName("Separator")] [Description("The character used to separate the values")] [DefaultValue(" ")] public string Separator { get; set; } public ConcatenationFormValueAggregator(IPropertyValueMapperService propertyValueMapperService) : base(propertyValueMapperService) { Separator = " "; } public override object GetValues(Dictionary<string, object> values, FormValueAggregatorContext context) { return string.Join(Separator, values.Select(x => ReadValue(x.Value))); } }
Registration
This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).
public void ConfigureServices(IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration) { services.AddNamed<IFormValueAggregator, ConcatenationFormValueAggregator>("ConcatenationFormValueAggregator"); }