Skip to content

Repository files navigation

BlazorDynamicForm

A lightweight, flexible form generator for Blazor applications that creates dynamic forms from annotated C# classes.

Features

  • Creates forms automatically from C# classes
  • Built-in validation through data annotations
  • Customizable form rendering and layout
  • Type-safe form handling

Installation

dotnet add package BlazorDynamicForm 

Quick Start

  1. Add Service in Program.cs
builder.Services.AddBlazorDynamicForm();
  1. Create a Model with Annotations
publicclassContactForm{[Required,Display(Name="Name")]publicstringName{get;set;}[EmailAddress]publicstringEmail{get;set;}[Phone,Display(Name="Phone Number")]publicstringPhoneNumber{get;set;}[TextArea]publicstringMessage{get;set;}}
  1. Use the DynamicForm Component
@usingBlazorDynamicForm.Components@usingTypeAnnotationParser
<DynamicFormScheme="@_formScheme"Data="_formData"OnValidSubmit="@HandleSubmit">
<SubmitTemplate>
<buttontype="submit"class="btn btn-primary">Submit</button>
</SubmitTemplate>
</DynamicForm>
@code{privateSchemeModel_formScheme;
privateIDictionary<string,object> _formData=newDictionary<string, object>();
protectedoverridevoidOnInitialized()
{varparser=newTypeAnnotationParser();
_formScheme=parser.Parse<ContactForm>();
}privatevoidHandleSubmit(IDictionary<string, object>data)
{// Handle form data}}
  1. Example

    Screenshot 2025-05-06 170325

Custom Attributes

BlazorDynamicForm provides additional attributes for enhanced form customization:

  • [TextArea] - Creates a multi-line text input
  • [Placeholder("Enter text...")] - Adds placeholder text
  • [Grid(6)] - Controls the layout grid width
  • [Name("Custom Field Name")] - Sets a custom field name
  • [MultipleSelect("Option1", "Option2", "Option3")] - Creates a dropdown with options

License

GPL-3.0

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

About

BlazorDynamicForm is a dynamic form generator.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

36 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages