diff --git a/components/form/Form.razor.cs b/components/form/Form.razor.cs index 286c5b0ca0..51c3c252b5 100644 --- a/components/form/Form.razor.cs +++ b/components/form/Form.razor.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using AntDesign.Forms; using AntDesign.Internal; @@ -61,7 +60,18 @@ public partial class Form : AntDomComponentBase, IForm public string Name { get; set; } [Parameter] - public TModel Model { get; set; } + public TModel Model + { + get { return _model; } + set + { + if (!(_model?.Equals(value) ?? false)) + { + _model = value; + _editContext = new EditContext(Model); + } + } + } [Parameter] public bool Loading { get; set; } @@ -95,6 +105,7 @@ public partial class Form : AntDomComponentBase, IForm private EditContext _editContext; private IList _formItems = new List(); private IList _controls = new List(); + private TModel _model; ColLayoutParam IForm.WrapperCol => WrapperCol; @@ -153,6 +164,7 @@ private async Task OnInvalidSubmit(EditContext editContext) public void Reset() { _controls.ForEach(item => item.Reset()); + _editContext = new EditContext(Model); } void IForm.AddFormItem(IFormItem formItem) @@ -188,5 +200,10 @@ public bool Validate() { return _editContext.Validate(); } + + public void ValidationReset() + { + _editContext = new EditContext(Model); + } } }