Skip to content

Commit

Permalink
(Form): splitting DataAnnotations and FluentValidation, auto label ge…
Browse files Browse the repository at this point in the history
…nerating and built-in complex type validation (#2073)
  • Loading branch information
capdiem authored Aug 2, 2024
1 parent 8f5624d commit 7532d99
Show file tree
Hide file tree
Showing 23 changed files with 751 additions and 355 deletions.
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

0 comments on commit 7532d99

Please sign in to comment.