refactor(module: form): make validate mode default to Complex (#4163)

This commit is contained in:
James Yeung 2024-09-04 07:10:30 +08:00 committed by GitHub
parent 4459d3ea8c
commit 063c24c8a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 11 deletions

View File

@ -19,10 +19,14 @@
{
<FormRulesValidator @ref="_rulesValidator" />
}
else
else if (Validate != null)
{
@Validator
}
else
{
<DataAnnotationsValidator />
}
<CascadingValue Value="this" Name="Form" TValue="IForm" IsFixed="@true">
@if (!string.IsNullOrEmpty(Size))
{

View File

@ -202,7 +202,7 @@ namespace AntDesign
/// Validator to use in the form. Used when <see cref="ValidateMode"/> is <c>FormValidateMode.Default</c> or <c>FormValidateMode.Complex</c>
/// </summary>
[Parameter]
public RenderFragment Validator { get; set; } = _defaultValidator;
public RenderFragment Validator { get; set; }
/// <summary>
/// Enable validation when component values change
@ -213,15 +213,10 @@ namespace AntDesign
/// <summary>
/// Which mode of validation the form should use
/// </summary>
/// <default value="FormValidateMode.Default"/>
/// <default value="FormValidateMode.Complex"/>
[Parameter]
public FormValidateMode ValidateMode { get; set; } = FormValidateMode.Default;
private static readonly RenderFragment _defaultValidator = builder =>
{
builder.OpenComponent<DataAnnotationsValidator>(0);
builder.CloseComponent();
};
[Obsolete("Will use both attributes and rules in the same time.")]
public FormValidateMode ValidateMode { get; set; } = FormValidateMode.Complex;
/// <summary>
/// If enabled, form submission is performed without fully reloading the page. This is equivalent to adding data-enhance to the form.
@ -494,7 +489,7 @@ namespace AntDesign
bool IForm.UseLocaleValidateMessage => UseLocaleValidateMessage;
private bool UseRulesValidator => UseLocaleValidateMessage || ValidateMode != FormValidateMode.Default;
private bool UseRulesValidator => UseLocaleValidateMessage && Validator == null;
private void BuildEditContext()
{