fix(module: form): DisplayName for FormItem will be not default to property name (#1738)

* fix(module: form): DisplayName for FormItem will be not default to property name

* add a demo for display name attribute
This commit is contained in:
James Yeung 2021-07-16 23:47:34 +08:00 committed by GitHub
parent 977633ae93
commit 1758181dea
2 changed files with 5 additions and 4 deletions

View File

@ -22,8 +22,8 @@ namespace AntDesign.Core.Reflection
this.PropertyInfo = propertyInfo;
this.RequiredAttribute = propertyInfo.GetCustomAttribute<RequiredAttribute>(true);
this.DisplayName = propertyInfo.GetCustomAttribute<DisplayNameAttribute>(true)?.DisplayName ??
propertyInfo.GetCustomAttribute<DisplayAttribute>(true)?.Name ??
propertyInfo.Name;
propertyInfo.GetCustomAttribute<DisplayAttribute>(true)?.Name;
this.PropertyName = PropertyInfo.Name;
}

View File

@ -1,12 +1,13 @@
@using System.ComponentModel.DataAnnotations;
@using System.Text.Json;
@using System.ComponentModel
<Form Model="@model"
OnFinish="OnFinish"
OnFinishFailed="OnFinishFailed"
LabelColSpan="8"
WrapperColSpan="16">
<FormItem Label="Username">
<FormItem>
<Input @bind-Value="@context.Username" />
</FormItem>
<FormItem Label="Password">
@ -25,7 +26,7 @@
{
public class Model
{
[Required]
[Required, DisplayName("User Name")]
public string Username { get; set; }
[Required]
public string Password { get; set; }