[英]How to make a component that have an EditForm and encapsulate the form and the validation inside?
I want to make a component that have a EditForm
and encapsulate the form and the validation inside of the component.我想制作一个具有
EditForm
的组件,并在组件内部封装表单和验证。
And I want to reuse this component anywhere in my application and submit it using any button.我想在我的应用程序中的任何地方重用这个组件并使用任何按钮提交它。
How can I submit a EditForm
from a button that is outside of it?如何从它外部的按钮提交
EditForm
?
Observation : I have searched for other answers like this one but the answer that is marked as accepted doesn't answer the question and that is why I'm making this new question.观察:我已经搜索过类似这样的其他答案,但标记为已接受的答案并没有回答问题,这就是我提出这个新问题的原因。
Instead of including the EditForm
in the component, create a component without the EditForm
and call a component's method on OnValidSubmit
不要在组件中包含
EditForm
,而是创建一个没有EditForm
的组件并在OnValidSubmit
上调用组件的方法
<EditForm OnValidSubmit="HandleValidSubmit">
<FormContentComponent @ref="_formContent" />
<button type="submit">submit</button>
</EditForm>
@code {
private FormContentComponent _formContent;
private void HandleValidSubmit()
{
_formContent.HandleValidSubmit();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.