feat: add one-to-many collection field support#89
Merged
Conversation
Implement AddCollectionField API for FormBuilder with fluent configuration, MudBlazor rendering component, and recursive validation support. New types: - ICollectionFieldConfiguration<TModel, TItem> / ICollectionFieldConfigurationBase - CollectionFieldConfiguration<TModel, TItem> - CollectionFieldBuilder<TModel, TItem> (fluent API) - CollectionFieldValidator<TModel, TItem> (min/max items + per-item validation) - CollectionFieldComponent (MudBlazor rendering with add/remove/reorder) - CollectionFieldRenderer (reflection-based generic bridge) Extended: - FormBuilder<TModel>.AddCollectionField() method - ICollectionFormConfiguration<TModel> interface (non-breaking) - FormConfiguration<TModel> implements ICollectionFormConfiguration - FormCraftComponent renders collection fields - DynamicFormValidator validates collection fields recursively Tests: 20 new tests covering builder API, validation, and full API pattern. Fixes #20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds collection field support to FormCraft, enabling one-to-many model forms (e.g., Order with OrderItems). Implements the fluent API proposed in #20.
Fixes #20
Changes
Core library (
FormCraft/)Forms/Core/ICollectionFieldConfiguration.cs— New generic interface defining collection field config (accessor, setter, min/max items, add/remove/reorder flags)Forms/Core/ICollectionFieldConfigurationBase.cs— Non-generic base interface for type-erased storage in collectionsForms/Core/CollectionFieldConfiguration.cs— Implementation with expression-based property access and setter compilationForms/Core/IFormConfiguration.cs— AddedICollectionFormConfiguration<TModel>interface (non-breaking);FormConfigurationnow implements it withCollectionFieldslistForms/Builders/CollectionFieldBuilder.cs— Fluent builder withAllowAdd(),AllowRemove(),AllowReorder(),WithMinItems(),WithMaxItems(),WithItemForm()Forms/Builders/FormBuilder.cs— AddedAddCollectionField<TItem>()methodForms/Validators/CollectionFieldValidator.cs— Validates min/max item counts and recursively validates each item's fieldsMudBlazor layer (
FormCraft.ForMudBlazor/)Features/CollectionField/CollectionFieldComponent.razor[.cs]— Renders collection with MudBlazor: add button, item cards with remove/reorder controls, per-item field renderingFeatures/CollectionField/CollectionFieldRenderer.cs— Reflection bridge from non-genericICollectionFieldConfigurationBaseto genericCollectionFieldComponent<TModel, TItem>Features/FormContainer/FormCraftComponent.razor— Renders collection fields after scalar fieldsFeatures/FormContainer/FormCraftComponent.razor.cs— AddedCollectionConfigurationproperty andHandleCollectionChangedmethodFeatures/Validation/DynamicFormValidator.cs— Extended to validate collection fields recursively on form submissionTests (
FormCraft.UnitTests/)Builders/CollectionFieldBuilderTests.cs— 15 tests covering builder API, chaining, defaults, accessor, item form, and full API pattern matching owner's proposalValidators/CollectionFieldValidatorTests.cs— 5 tests covering min/max validation and per-item recursive validationTesting
Discovered Issues
Titleattribute onMudIconButtontriggers MUD0002 warnings in the MudBlazor analyzer (pre-existing pattern in the codebase, not introduced by this PR)Items[0].ProductName) are handled at the component level rather than through Blazor's built-in field identifier system — this works but could be improved in a future iteration