-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Form): splitting DataAnnotations and FluentValidation, auto label ge…
…nerating and built-in complex type validation (#2073)
- Loading branch information
Showing
23 changed files
with
751 additions
and
355 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
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; | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
src/Masa.Blazor/Components/Form/EditContext/EditContextExtensions.cs
This file was deleted.
Oops, something went wrong.
298 changes: 0 additions & 298 deletions
298
src/Masa.Blazor/Components/Form/EditContext/ValidationEventSubscriptions.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.