mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-02 12:07:44 +08:00
feat(module: form): add IsModified
property (#327)
* feat: is form modified property and method exposed subject: new method for form context, Is form modified * fix: interface and doc Co-authored-by: Ratomir Vukadin <ratomirvu@maestralsolutions.com> Co-authored-by: James Yeung <shunjiey@hotmail.com>
This commit is contained in:
parent
cd2901fa7b
commit
04166ba276
@ -39,6 +39,8 @@ namespace AntDesign
|
||||
[Parameter]
|
||||
public EventCallback<EditContext> OnFinishFailed { get; set; }
|
||||
|
||||
public bool IsModified => _editContext.IsModified();
|
||||
|
||||
private EditContext _editContext;
|
||||
private IList<IFormItem> _formItems = new List<IFormItem>();
|
||||
private IList<IControlValueAccessor> _controls = new List<IControlValueAccessor>();
|
||||
@ -48,6 +50,7 @@ namespace AntDesign
|
||||
ColLayoutParam IForm.LabelCol => LabelCol;
|
||||
|
||||
EditContext IForm.EditContext => _editContext;
|
||||
|
||||
string IForm.Size => Size;
|
||||
|
||||
protected override void OnInitialized()
|
||||
@ -58,13 +61,6 @@ namespace AntDesign
|
||||
_editContext = new EditContext(Model);
|
||||
}
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
base.OnParametersSet();
|
||||
|
||||
SetClass();
|
||||
}
|
||||
|
||||
protected void SetClass()
|
||||
{
|
||||
this.ClassMapper.Clear()
|
||||
@ -96,5 +92,6 @@ namespace AntDesign
|
||||
{
|
||||
return _editContext.Validate();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,15 @@ namespace AntDesign.Internal
|
||||
internal ColLayoutParam LabelCol { get; }
|
||||
|
||||
internal EditContext EditContext { get; }
|
||||
|
||||
internal string Size { get; }
|
||||
|
||||
internal void AddFormItem(IFormItem formItem);
|
||||
|
||||
internal void AddControl(IControlValueAccessor valueAccessor);
|
||||
|
||||
bool IsModified { get; }
|
||||
|
||||
void Reset();
|
||||
|
||||
bool Validate();
|
||||
|
14
site/AntBlazor.Docs/Demos/Form/demo/FormContext.md
Normal file
14
site/AntBlazor.Docs/Demos/Form/demo/FormContext.md
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
order: 6
|
||||
title:
|
||||
zh-CN: 判断表单是否被修改
|
||||
en-US: Check if the form has been modified
|
||||
---
|
||||
|
||||
## zh-CN
|
||||
|
||||
通过 `IForm.IsModified` 判断表单修改。
|
||||
|
||||
## en-US
|
||||
|
||||
Check if the form has been modified by using `IForm.IsModified`.
|
48
site/AntBlazor.Docs/Demos/Form/demo/FormContext.razor
Normal file
48
site/AntBlazor.Docs/Demos/Form/demo/FormContext.razor
Normal file
@ -0,0 +1,48 @@
|
||||
@using System.ComponentModel.DataAnnotations;
|
||||
@using System.Text.Json;
|
||||
|
||||
<Form @ref="form" Model="@model"
|
||||
LabelCol="new ColLayoutParam { Span = 8 }"
|
||||
WrapperCol="new ColLayoutParam { Span = 16 }"
|
||||
OnFinish="OnFinish"
|
||||
OnFinishFailed="OnFinishFailed">
|
||||
<FormItem Label="Username">
|
||||
<Input @bind-Value="@context.Username" />
|
||||
</FormItem>
|
||||
<FormItem Label="Password">
|
||||
<InputPassword @bind-Value="@context.Password" />
|
||||
</FormItem>
|
||||
<FormItem WrapperCol="new ColLayoutParam{ Offset = 8, Span = 16 }">
|
||||
<Checkbox @bind-Value="context.RememberMe">Remember me</Checkbox>
|
||||
</FormItem>
|
||||
<FormItem WrapperCol="new ColLayoutParam{ Offset = 8, Span = 16 }">
|
||||
<Button Type="@ButtonType.Primary" HtmlType="submit" Disabled="!form.IsModified">
|
||||
Submit
|
||||
</Button>
|
||||
</FormItem>
|
||||
</Form>
|
||||
@code
|
||||
{
|
||||
public class Model
|
||||
{
|
||||
[Required]
|
||||
public string Username { get; set; }
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
public bool RememberMe { get; set; } = true;
|
||||
}
|
||||
|
||||
Form<Model> form;
|
||||
|
||||
private Model model = new Model();
|
||||
|
||||
private void OnFinish(EditContext editContext)
|
||||
{
|
||||
Console.WriteLine($"Success:{JsonSerializer.Serialize(model)}");
|
||||
}
|
||||
|
||||
private void OnFinishFailed(EditContext editContext)
|
||||
{
|
||||
Console.WriteLine($"Failed:{JsonSerializer.Serialize(model)}");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user