I want to make a component that have a EditForm and encapsulate the form and the validation inside of the component.
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?
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 OnValidSubmit="HandleValidSubmit">
<FormContentComponent @ref="_formContent" />
<button type="submit">submit</button>
</EditForm>
@code {
private FormContentComponent _formContent;
private void HandleValidSubmit()
{
_formContent.HandleValidSubmit();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With