mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-02 03:57:38 +08:00
fix(module: input): fix incorrectly validation and required message (#3474)
* fix(module: input): fix incorrectly validation and required message * add tests
This commit is contained in:
parent
bd8d3fe3e4
commit
54d821e6ec
@ -705,7 +705,7 @@ namespace AntDesign
|
||||
|
||||
if (FormItem?.IsRequiredByValidation ?? false)
|
||||
{
|
||||
builder.AddAttribute(65, "required", "required");
|
||||
builder.AddAttribute(65, "aria-required", true);
|
||||
}
|
||||
|
||||
// onchange 和 onblur 事件会导致点击 OnSearch 按钮时不触发 Click 事件,暂时取消这两个事件
|
||||
|
@ -1,9 +1,13 @@
|
||||
@inherits AntDesignTestBase
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@inherits AntDesignTestBase
|
||||
@code {
|
||||
|
||||
class Model
|
||||
{
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
[Required]
|
||||
public string? RequiredField { get; set; }
|
||||
}
|
||||
Model _model = new();
|
||||
AntDesign.Form<Model>? _form;
|
||||
@ -68,4 +72,27 @@
|
||||
handlerExecuted.Should().BeTrue();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
[Fact]
|
||||
public void Form_EditContext_Build_Required()
|
||||
{
|
||||
//Arrange
|
||||
JSInterop.Setup<AntDesign.JsInterop.Window>(JSInteropConstants.GetWindow)
|
||||
.SetResult(new AntDesign.JsInterop.Window());
|
||||
|
||||
var cut = Render<AntDesign.Form<Model>>(
|
||||
@<AntDesign.Form @ref="@_form" Model="@_model" >
|
||||
<AntDesign.FormItem Label="RequiredField">
|
||||
<AntDesign.Input @bind-Value=@context.RequiredField DebounceMilliseconds="0" />
|
||||
</AntDesign.FormItem>
|
||||
</AntDesign.Form>
|
||||
);
|
||||
//Act
|
||||
var hasAriaRequried=cut.Find("input").HasAttribute("aria-required");
|
||||
|
||||
//Assert
|
||||
hasAriaRequried.Should().BeTrue();
|
||||
}
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue
Block a user