How to make a component that have an EditForm and encapsulate the form and the validation inside?

前端 未结 1 1181
时光说笑
时光说笑 2020-12-21 14:24

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

相关标签:
1条回答
  • 2020-12-21 15:00

    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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题