ant-design-blazor/components/config-provider/ConfigProvider.razor.cs
笨木头 ec45abc4d7 feat(module: form): support set validation rules on FormItem (#1516)
* feat(module: form): support set validation rules on FormItem(not complete yet)

* refactor(module: form): optimized code

* feat(module: form): support Whitespace rule

* feat(module: form): support [message、pattern、transform、validator、whitespace] rules

* feat(module: form): support type rule

* feat(module: form): support [defaultField、oneOf、fields、type] rules

* feat(module: form): support custome validate messages(without test)

* test(module: form): complete RuleValidate_ValidateMessages test

* feat(module: form): complete DynamicRule demo, refactor code, fix bugs

* feat(module: form): support ValidateMessages param

* doc(module: form): add "Rules" and "ValidateMessages" docs

* fix: Rule.Max's errorMessage is wrong

* refactor: rename Rule to FormValidationRule

* test: rename Rule to FormValidationRule

* chore: refactor code and rename classes

* Update ValidateMode.razor

* Update FormValidateErrorMessages.cs

* Update FormValidateHelper.cs

Co-authored-by: James Yeung <shunjiey@hotmail.com>
2021-05-28 09:08:42 +00:00

61 lines
1.5 KiB
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
namespace AntDesign
{
public partial class ConfigProvider : AntComponentBase
{
[Parameter]
public string Direction
{
get => _direction;
set
{
if (_direction != value)
{
_direction = value;
_waitingDirectionUpdate = true;
}
}
}
[Parameter]
public FormConfig Form { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
[Inject] public ConfigService ConfigService { get; set; }
private string _direction;
private bool _waitingDirectionUpdate;
private bool _afterFirstRender;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
_afterFirstRender = true;
}
if (_afterFirstRender)
{
if (_waitingDirectionUpdate)
{
_waitingDirectionUpdate = false;
await ChangeDirection(_direction);
}
}
}
public async Task ChangeDirection(string direction)
{
_direction = direction?.ToUpperInvariant();
await ConfigService.ChangeDirection(_direction);
await InvokeAsync(StateHasChanged);
}
}
}