diff --git a/src/components/modalWithForm/index.tsx b/src/components/modalWithForm/index.tsx index bf709f218..d7963b29f 100644 --- a/src/components/modalWithForm/index.tsx +++ b/src/components/modalWithForm/index.tsx @@ -19,6 +19,7 @@ export interface ModalProps { centered?: boolean; cancelButtonProps?: ButtonProps; notSubmitCloseModal?: boolean; + layout?: 'horizontal' | 'vertical' | 'inline'; } interface ModalState { @@ -31,18 +32,22 @@ function ModalWithForm(FormComponent: any) { constructor(props: any) { super(props); this.state = { - form: null + form: null, }; } - componentDidMount(): void { - this.setState({ - form: this.formRef.current - }); + + componentDidUpdate(prevProps: Readonly, prevState: Readonly): void { + if(this.props.visible && prevProps.visible != this.props.visible){ + this.formRef.current && this.setState({ + form: this.formRef.current, + }); + } } + okHandler = async () => { const { record, notSubmitCloseModal = false, onSubmit, hideModelHandler } = this.props; try { - const values = await this.formRef.current?.validateFields() + const values = await this.formRef.current?.validateFields(); onSubmit(values, record); notSubmitCloseModal && hideModelHandler(); } catch (error) {} @@ -62,27 +67,28 @@ function ModalWithForm(FormComponent: any) { okType, footer, centered, - cancelButtonProps + cancelButtonProps, + layout = 'vertical', } = this.props; const { form } = this.state; return ( -
- - {form && } - -
+ +
+ {form && } + +
); } };