An ABP module helps users to define and use dynamic forms at runtime.
-
Install the following NuGet packages. (see how)
- EasyAbp.DynamicForm.Application
- EasyAbp.DynamicForm.Application.Contracts
- EasyAbp.DynamicForm.Domain
- EasyAbp.DynamicForm.Domain.Shared
- EasyAbp.DynamicForm.EntityFrameworkCore
- EasyAbp.DynamicForm.HttpApi
- EasyAbp.DynamicForm.HttpApi.Client
- EasyAbp.DynamicForm.Web
-
Add
DependsOn(typeof(DynamicFormXxxModule))
attribute to configure the module dependencies. (see how) -
Add
builder.ConfigureDynamicForm();
to theOnModelCreating()
method in MyProjectMigrationsDbContext.cs. -
Add EF Core migrations and update your database. See: ABP document.
-
Configure the module.
Configure<DynamicFormOptions>(options => { options.AddOrUpdateFormDefinition(new FormDefinition("InternalForm", "Internal Form")); });
-
(Optional) Create a custom
FormTemplateOperationAuthorizationHandler
to determine who can create/read/update/delete the form templates. ( see sample) Users who haveEasyAbp.DynamicForm.FormTemplate.Manage
permission can skip the check. -
(Optional) Create a custom
FormOperationAuthorizationHandler
to determine who can create/read/update/delete the forms. ( see sample) Users who haveEasyAbp.DynamicForm.Form.Manage
permission can skip the check. -
Try to create a form template.
-
Try to create a form.
This way, we don't install the whole dynamic form module (no extra entities installed). Instead, we enhance the existing entities to support the dynamic forms feature.
-
Install only the following modules:
- EasyAbp.DynamicForm.Domain.Core
- EasyAbp.DynamicForm.Domain.Shared
- EasyAbp.DynamicForm.EntityFrameworkCore.Shared
-
Make your entities contain the form item information.
public class BookRental : AggregateRoot<Guid> { public string BookName { get; set; } public List<BookRentalFormItem> FormItems { get; set; } = new(); } public class BookRentalFormItem : Entity, IFormItemMetadata { // properties... }
public class BookRentalRequest : AggregateRoot<Guid> { public Guid BookRentalId { get; set; } public Guid RenterUserId { get; set; } public List<BookRentalRequestFormItem> FormItems { get; set; } = new(); } public class BookRentalRequestFormItem : Entity, IFormItem // implement IFormItemMetadata if need { // properties... }
protected override void OnModelCreating(ModelBuilder builder) { // ... builder.Entity<BookRentalFormItem>(b => { b.ToTable(MyProjectConsts.DbTablePrefix + "BookRentalFormItems", MyProjectConsts.DbSchema); b.TryConfigureAvailableValues(); // add this configuration. b.ConfigureByConvention(); b.HasKey(x => new { x.BookRentalId, x.Name }); }); }
-
Validate when changing the form item templates.
await dynamicFormValidator.ValidateTemplatesAsync(bookRental.FormItems);
-
Validate when changing the form items.
await dynamicFormValidator.ValidateValuesAsync(bookRental.FormItems, bookRentalRequest.FormItems);
- Number input form item type.
- Checkbox form item type.
- Date picker form item type.
- Listbox form item type.
- Drop-down listbox form item type.