Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Form): splitting DataAnnotations and FluentValidation, auto label generating and built-in complex type validation #2073

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
56 changes: 56 additions & 0 deletions src/Masa.Blazor/Components/Form/AutoLabelOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using IComponent = Microsoft.AspNetCore.Components.IComponent;

namespace Masa.Blazor.Components.Form;

/// <summary>
/// The settings for automatically generating the label of the form input.
/// Should be placed in the <see cref="MForm"/> component.
/// </summary>
public class AutoLabelOptions : IComponent
{
[CascadingParameter] private MForm? Form { get; set; }

/// <summary>
/// The attribute type to get the display name.
/// Supported types are <see cref="DisplayAttribute"/> and <see cref="System.ComponentModel.DisplayNameAttribute"/>.
/// </summary>
[Parameter]
public Type? AttributeType { get; set; } = typeof(DisplayNameAttribute);

private bool _init;

public void Attach(RenderHandle renderHandle)
{
}

public Task SetParametersAsync(ParameterView parameters)
{
if (_init)
{
return Task.CompletedTask;
}

_init = true;

if (parameters.TryGetValue(nameof(Form), out MForm? form))
{
Form = form;
}

if (Form is null)
{
return Task.CompletedTask;
}

if (parameters.TryGetValue(nameof(AttributeType), out Type? attributeType))
{
AttributeType = attributeType;
}

Form.LabelAttributeType = AttributeType;

return Task.CompletedTask;
}
}

This file was deleted.

This file was deleted.

Loading
Loading