mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-05 05:29:47 +08:00
!2252 feat(#I4O30L): Display support auto show Label when inside ValidateForm
* feat: Display 组件支持嵌套表单内自动显示 Text 特性
This commit is contained in:
parent
6323954ec4
commit
d6226c75f8
@ -65,6 +65,18 @@ namespace BootstrapBlazor.Components
|
||||
[Parameter]
|
||||
public string? DisplayText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得 ValidateForm 实例
|
||||
/// </summary>
|
||||
[CascadingParameter]
|
||||
protected ValidateForm? ValidateForm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得 IShowLabel 实例
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "EidtorForm")]
|
||||
protected IShowLabel? EditorForm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SetParametersAsync 方法
|
||||
/// </summary>
|
||||
@ -92,7 +104,16 @@ namespace BootstrapBlazor.Components
|
||||
{
|
||||
base.OnParametersSet();
|
||||
|
||||
IsShowLabel = ShowLabel ?? false;
|
||||
// 显式设置显示标签时一定显示
|
||||
var showLabel = ShowLabel;
|
||||
|
||||
// 组件自身未设置 ShowLabel 取 EditorForm/VaidateForm 级联值
|
||||
if (ShowLabel == null && (EditorForm != null || ValidateForm != null))
|
||||
{
|
||||
showLabel = EditorForm?.ShowLabel ?? ValidateForm?.ShowLabel ?? true;
|
||||
}
|
||||
|
||||
IsShowLabel = showLabel ?? false;
|
||||
|
||||
// 设置显示标签时未提供 DisplayText 通过双向绑定获取 DisplayName
|
||||
if (IsShowLabel && DisplayText == null && FieldIdentifier.HasValue)
|
||||
|
@ -202,18 +202,6 @@ namespace BootstrapBlazor.Components
|
||||
[CascadingParameter]
|
||||
protected EditContext? CascadedEditContext { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得 ValidateForm 实例
|
||||
/// </summary>
|
||||
[CascadingParameter]
|
||||
protected ValidateForm? ValidateForm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得 IShowLabel 实例
|
||||
/// </summary>
|
||||
[CascadingParameter(Name = "EidtorForm")]
|
||||
protected IShowLabel? EditorForm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parses a string to create an instance of <typeparamref name="TValue"/>. Derived classes can override this to change how
|
||||
/// <see cref="CurrentValueAsString"/> interprets incoming values.
|
||||
@ -304,22 +292,7 @@ namespace BootstrapBlazor.Components
|
||||
/// </summary>
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
// 显式设置显示标签时一定显示
|
||||
var showLabel = ShowLabel;
|
||||
|
||||
// 组件自身未设置 ShowLabel 取 EditorForm/VaidateForm 级联值
|
||||
if (ShowLabel == null && (EditorForm != null || ValidateForm != null))
|
||||
{
|
||||
showLabel = EditorForm?.ShowLabel ?? ValidateForm?.ShowLabel ?? true;
|
||||
}
|
||||
|
||||
IsShowLabel = showLabel ?? false;
|
||||
|
||||
// 绑定属性值获取 DisplayName
|
||||
if (IsShowLabel && DisplayText == null && FieldIdentifier.HasValue)
|
||||
{
|
||||
DisplayText = FieldIdentifier.Value.GetDisplayName();
|
||||
}
|
||||
base.OnParametersSet();
|
||||
|
||||
Required = (IsNeedValidate && !string.IsNullOrEmpty(DisplayText) && (ValidateForm?.ShowRequiredMark ?? false) && IsRequired()) ? "true" : null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user