mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-02 12:07:44 +08:00
fix(module: form): fix input components inside customized form control (#1662)
This commit is contained in:
parent
10e13c5059
commit
a06fd5c2e5
@ -328,6 +328,8 @@ namespace AntDesign
|
||||
EditContext.OnValidationStateChanged -= _validationStateChangedHandler;
|
||||
}
|
||||
|
||||
Form?.RemoveControl(this);
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
|
@ -182,6 +182,14 @@ namespace AntDesign
|
||||
this._controls.Add(valueAccessor);
|
||||
}
|
||||
|
||||
void IForm.RemoveControl(IControlValueAccessor valueAccessor)
|
||||
{
|
||||
if (_controls.Contains(valueAccessor))
|
||||
{
|
||||
this._controls.Remove(valueAccessor);
|
||||
}
|
||||
}
|
||||
|
||||
public void Submit()
|
||||
{
|
||||
var isValid = _editContext.Validate();
|
||||
|
@ -108,6 +108,8 @@ namespace AntDesign
|
||||
private ClassMapper _labelClassMapper = new ClassMapper();
|
||||
private AntLabelAlignType? FormLabelAlign => LabelAlign ?? Form.LabelAlign;
|
||||
|
||||
private EventHandler<ValidationStateChangedEventArgs> _validationStateChangedHandler;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
@ -191,8 +193,20 @@ namespace AntDesign
|
||||
return Required ? $"{_prefixCls}-required" : _labelCls;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (CurrentEditContext != null && _validationStateChangedHandler != null)
|
||||
{
|
||||
CurrentEditContext.OnValidationStateChanged -= _validationStateChangedHandler;
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
void IFormItem.AddControl<TValue>(AntInputComponentBase<TValue> control)
|
||||
{
|
||||
if (_control != null) return;
|
||||
|
||||
if (control.FieldIdentifier.Model == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Please use @bind-Value (or @bind-Values for selected components) in the control with generic type `{typeof(TValue)}`.");
|
||||
@ -200,7 +214,7 @@ namespace AntDesign
|
||||
|
||||
this._control = control;
|
||||
|
||||
CurrentEditContext.OnValidationStateChanged += (s, e) =>
|
||||
_validationStateChangedHandler = (s, e) =>
|
||||
{
|
||||
control.ValidationMessages = CurrentEditContext.GetValidationMessages(control.FieldIdentifier).Distinct().ToArray();
|
||||
this._isValid = !control.ValidationMessages.Any();
|
||||
@ -208,6 +222,8 @@ namespace AntDesign
|
||||
StateHasChanged();
|
||||
};
|
||||
|
||||
CurrentEditContext.OnValidationStateChanged += _validationStateChangedHandler;
|
||||
|
||||
_formValidationMessages = builder =>
|
||||
{
|
||||
var i = 0;
|
||||
|
@ -20,6 +20,8 @@ namespace AntDesign.Internal
|
||||
|
||||
internal void AddControl(IControlValueAccessor valueAccessor);
|
||||
|
||||
internal void RemoveControl(IControlValueAccessor valueAccessor);
|
||||
|
||||
internal bool ValidateOnChange { get; }
|
||||
|
||||
event Action<IForm> OnFinishEvent;
|
||||
|
Loading…
Reference in New Issue
Block a user