fix(module: form): use FormItem label or property displayname as the label of error messages (#4074)

This commit is contained in:
James Yeung 2024-08-08 22:27:18 +08:00 committed by GitHub
parent 8f7f43109b
commit cbef6000e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 8 deletions

View File

@ -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>

View File

@ -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,
};