mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-02 03:57:38 +08:00
fix(module: form): use FormItem label or property displayname as the label of error messages (#4074)
This commit is contained in:
parent
8f7f43109b
commit
cbef6000e0
@ -2,12 +2,9 @@
|
||||
@inherits AntDomComponentBase
|
||||
@using AntDesign.Internal;
|
||||
|
||||
@{
|
||||
var realLabel = Label ?? _propertyReflector?.DisplayName;
|
||||
}
|
||||
<div class="@ClassMapper.Class" style="@Style" id="@Id">
|
||||
<Row Class="ant-form-item-row">
|
||||
@if (!string.IsNullOrEmpty(realLabel) || LabelTemplate != null)
|
||||
@if (!string.IsNullOrEmpty(DisplayName) || LabelTemplate != null)
|
||||
{
|
||||
<AntDesign.Col @attributes="GetLabelColAttributes()" Class="@_labelClassMapper.Class">
|
||||
@if (LabelTemplate != null)
|
||||
@ -17,7 +14,7 @@
|
||||
else
|
||||
{
|
||||
<label class=@GetLabelClass() style="@LabelStyle">
|
||||
@realLabel
|
||||
@DisplayName
|
||||
@if (Form?.RequiredMark == FormRequiredMark.Optional && !IsRequired)
|
||||
{
|
||||
<span class="ant-form-item-optional">@Form.Locale.Optional</span>
|
||||
|
@ -184,6 +184,8 @@ namespace AntDesign
|
||||
|
||||
private AntLabelAlignType? FormLabelAlign => LabelAlign ?? Form?.LabelAlign;
|
||||
|
||||
private string DisplayName => Label ?? _propertyReflector?.DisplayName;
|
||||
|
||||
private FieldIdentifier _fieldIdentifier;
|
||||
private Func<object, object> _fieldValueGetter;
|
||||
|
||||
@ -444,8 +446,6 @@ namespace AntDesign
|
||||
|
||||
var results = new List<ValidationResult>();
|
||||
|
||||
var displayName = string.IsNullOrEmpty(Label) ? _fieldIdentifier.FieldName : Label;
|
||||
|
||||
if (_fieldValueGetter != null)
|
||||
{
|
||||
var propertyValue = _fieldValueGetter.Invoke(_fieldIdentifier.Model);
|
||||
@ -459,7 +459,7 @@ namespace AntDesign
|
||||
Rule = rule,
|
||||
Value = propertyValue,
|
||||
FieldName = _fieldIdentifier.FieldName,
|
||||
DisplayName = displayName,
|
||||
DisplayName = DisplayName,
|
||||
ValidateMessages = validateMessages,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user