Form module
The Form module allows you to create or modify entities of type item by showing their data in a form.
To activate a section with a Form module, the settings in the relevant data section must be configured by specifying the form, the database table and the related fields that will be displayed in the parent list.
The module can be used with the DataWeb configuration only but, if necessary, it can be customized in all its functions by setting a class inherited from the base ModuleForm and overwriting the methods concerned. The new class is set in the relevant settings in DataWeb.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DataWeb.Data;
using DataWeb.Structure;
using DataWeb.Structure.Modules;
namespace App.DataWeb.Structure.Modules
{
public class ModuleSupportTicketForm(Section section, NavigationContext navigationContext, IServiceProvider serviceProvider) : ModuleForm(section, navigationContext, serviceProvider)
{
public override Task ProcessOnSaveDataAsync(Item item, Item.SectionPart sectionPart, List<Form.ProvidedValue> providedValues, CancellationToken cancellationToken = default)
{
sectionPart.SectionData["IsNewMessage"] = false;
return Task.CompletedTask;
}
}
}
In this example, we are supplementing the data from the form with an additional value before saving it to the database.
This table can be used as a reference to identify areas of the ModuleForm base class that can be customized by creating a derived class.
Method | Description | Possible customization |
---|---|---|
ValidateAsync | Validate the form data for a specific item. Verifies the values provided and returns any validation errors. | Overwritable to add custom validation rules or to extend validation behavior with additional logic. |
SaveAsync | Save the form data for a specific item. Update data, validate changes, and log audit events. | Overwritable to add custom logic while saving, such as extra field updates, notifications, or additional processing. |
ProcessOnSaveDataAsync | Performs additional processing while saving form data. | Overwritable to perform specific post-save logic, such as updating derived fields or performing complex calculations. |
IsCompletedAsync | Determines whether the module section is completed for a specific item. Returns true if the section is validated, otherwise false. | Overridable to add custom completion rules, such as controls on specific data or dependencies between fields. |
CloneAsync | Clone the form section data, including any versions, from one item to another. | Overwritable to customize cloning logic, such as modifying copied data or managing entity relationships. |